Skip to content

Commit 0f1c05d

Browse files
committed
Cancel the internal isset method, etc
1 parent b4ead0f commit 0f1c05d

File tree

1 file changed

+11
-19
lines changed

1 file changed

+11
-19
lines changed

DictionaryList/DictionaryList.cs

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public TValue this[int index]
101101
ThrowHelper.ThrowArgumentOutOfRangeException(index);
102102
}
103103
// definitely in range
104-
if (!IndexIsSet(index))
104+
if (!_issetLookup[index])
105105
{
106106
throw new KeyNotFoundException($"The given index {index} was unset in the list.");
107107
}
@@ -114,7 +114,7 @@ public TValue this[int index]
114114
// out of range!
115115
ThrowHelper.ThrowArgumentOutOfRangeException(index);
116116
}
117-
if (!IndexIsSet(index))
117+
if (!_issetLookup[index])
118118
{
119119
// adding items during iteration is not allowed!
120120
_version++;
@@ -166,14 +166,15 @@ public void UnsetAt(int index)
166166
{
167167
ThrowHelper.ThrowArgumentOutOfRangeException(index);
168168
}
169-
if (!IndexIsSet(index))
169+
ref var isset = ref _issetLookup[index];
170+
if (!isset)
170171
{
171172
return;
172173
}
173174

174175
_items[index] = default!;
175176
_actualCount--;
176-
_issetLookup[index] = false;
177+
isset = false;
177178
}
178179

179180
/// <summary>
@@ -188,14 +189,6 @@ public bool ContainsIndex(int index)
188189
return false;
189190
}
190191
// we might have it
191-
return IndexIsSet(index);
192-
}
193-
194-
[MethodImpl(MethodImplOptions.AggressiveInlining)]
195-
internal bool IndexIsSet(int index)
196-
{
197-
// does not check for index range, for internal use where we are very sure it does not cause range overflow
198-
// we force-inline it to waive this method call
199192
return _issetLookup[index];
200193
}
201194

@@ -247,7 +240,7 @@ public void CompactAndTrimExcess()
247240
var newIndex = 0;
248241
for (var index = 0; index < _size; index++)
249242
{
250-
if (!IndexIsSet(index))
243+
if (!_issetLookup[index])
251244
{
252245
// this is an empty slot; skip
253246
continue;
@@ -288,18 +281,17 @@ internal DictionaryListEnumerator(DictionaryList<TValue> dictList)
288281

289282
public bool MoveNext()
290283
{
291-
var iterIndex = _index;
292284
var theDictList = _dictList;
293-
while (_version == theDictList._version && (uint)iterIndex < (uint)theDictList._size)
285+
while (_version == theDictList._version && (uint)_index < (uint)theDictList._size)
294286
{
295-
if (!theDictList.IndexIsSet(iterIndex))
287+
if (!theDictList._issetLookup[_index])
296288
{
297289
// not set; find the next one!
298-
iterIndex++;
290+
_index++;
299291
continue;
300292
}
301-
_current = new KeyValuePair<int, TValue>(iterIndex, theDictList[iterIndex]);
302-
_index = iterIndex + 1;
293+
_current = new KeyValuePair<int, TValue>(_index, theDictList[_index]);
294+
_index++;
303295
return true;
304296
}
305297

0 commit comments

Comments
 (0)