internal void AssignNameSlots()
{
if (_capnames != null)
{
for (int i = 0; i < _capnamelist.Count; i++)
{
while (IsCaptureSlot(_autocap))
_autocap++;
string name = _capnamelist[i];
int pos = (int)_capnames[name];
_capnames[name] = _autocap;
NoteCaptureSlot(_autocap, pos);
_autocap++;
}
}
// if the caps array has at least one gap, construct the list of used slots
if (_capcount < _captop)
{
_capnumlist = new int[_capcount];
int i = 0;
// Manual use of IDictionaryEnumerator instead of foreach to avoid DictionaryEntry box allocations.
IDictionaryEnumerator de = _caps.GetEnumerator();
while (de.MoveNext())
{
_capnumlist[i++] = (int)de.Key;
}
Array.Sort(_capnumlist, Comparer<int>.Default);
}
// merge capsnumlist into capnamelist
if (_capnames != null || _capnumlist != null)
{
List<string> oldcapnamelist;
int next;
int k = 0;
if (_capnames == null)
{
oldcapnamelist = null;
_capnames = new Hashtable();
_capnamelist = new List<string>();
next = -1;
}
else
{
oldcapnamelist = _capnamelist;
_capnamelist = new List<string>();
next = (int)_capnames[oldcapnamelist[0]];
}
for (int i = 0; i < _capcount; i++)
{
int j = (_capnumlist == null) ? i : (int)_capnumlist[i];
if (next == j)
{
_capnamelist.Add(oldcapnamelist[k++]);
next = (k == oldcapnamelist.Count) ? -1 : (int)_capnames[oldcapnamelist[k]];
}
else
{
string str = Convert.ToString(j, _culture);
_capnamelist.Add(str);
_capnames[str] = j;
}
}
}
}