mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-15 14:54:09 +02:00
Merge pull request #1276 from disarray2077/patch-1
Optimize the remove method of dictionary enumerator
This commit is contained in:
commit
cf7c5c3869
1 changed files with 40 additions and 3 deletions
|
@ -578,6 +578,43 @@ namespace System.Collections
|
||||||
return oldPtr;
|
return oldPtr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private bool RemoveEntry(int32 hashCode, int_cosize index)
|
||||||
|
{
|
||||||
|
if (mBuckets != null)
|
||||||
|
{
|
||||||
|
int bucket = hashCode % (int_cosize)mAllocSize;
|
||||||
|
int lastIndex = -1;
|
||||||
|
|
||||||
|
for (int_cosize i = mBuckets[bucket]; i >= 0; lastIndex = i, i = mEntries[i].mNext)
|
||||||
|
{
|
||||||
|
if (i == index)
|
||||||
|
{
|
||||||
|
if (lastIndex < 0)
|
||||||
|
{
|
||||||
|
mBuckets[bucket] = mEntries[index].mNext;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
mEntries[lastIndex].mNext = mEntries[index].mNext;
|
||||||
|
}
|
||||||
|
mEntries[index].mHashCode = -1;
|
||||||
|
mEntries[index].mNext = mFreeList;
|
||||||
|
#if BF_ENABLE_REALTIME_LEAK_CHECK
|
||||||
|
mEntries[index].mKey = default;
|
||||||
|
mEntries[index].mValue = default;
|
||||||
|
#endif
|
||||||
|
mFreeList = index;
|
||||||
|
mFreeCount++;
|
||||||
|
#if VERSION_DICTIONARY
|
||||||
|
mVersion++;
|
||||||
|
#endif
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
public bool Remove(TKey key)
|
public bool Remove(TKey key)
|
||||||
{
|
{
|
||||||
if (mBuckets != null)
|
if (mBuckets != null)
|
||||||
|
@ -901,7 +938,7 @@ namespace System.Collections
|
||||||
public void Remove() mut
|
public void Remove() mut
|
||||||
{
|
{
|
||||||
int_cosize curIdx = mIndex - 1;
|
int_cosize curIdx = mIndex - 1;
|
||||||
mDictionary.Remove(mDictionary.mEntries[curIdx].mKey);
|
mDictionary.RemoveEntry(mDictionary.mEntries[curIdx].mHashCode, curIdx);
|
||||||
#if VERSION_DICTIONARY
|
#if VERSION_DICTIONARY
|
||||||
mVersion = mDictionary.mVersion;
|
mVersion = mDictionary.mVersion;
|
||||||
#endif
|
#endif
|
||||||
|
@ -1052,7 +1089,7 @@ namespace System.Collections
|
||||||
public void Remove() mut
|
public void Remove() mut
|
||||||
{
|
{
|
||||||
int_cosize curIdx = mIndex - 1;
|
int_cosize curIdx = mIndex - 1;
|
||||||
mDictionary.Remove(mDictionary.mEntries[curIdx].mKey);
|
mDictionary.RemoveEntry(mDictionary.mEntries[curIdx].mHashCode, curIdx);
|
||||||
#if VERSION_DICTIONARY
|
#if VERSION_DICTIONARY
|
||||||
mVersion = mDictionary.mVersion;
|
mVersion = mDictionary.mVersion;
|
||||||
#endif
|
#endif
|
||||||
|
@ -1158,7 +1195,7 @@ namespace System.Collections
|
||||||
public void Remove() mut
|
public void Remove() mut
|
||||||
{
|
{
|
||||||
int_cosize curIdx = mIndex - 1;
|
int_cosize curIdx = mIndex - 1;
|
||||||
mDictionary.Remove(mDictionary.mEntries[curIdx].mKey);
|
mDictionary.RemoveEntry(mDictionary.mEntries[curIdx].mHashCode, curIdx);
|
||||||
#if VERSION_DICTIONARY
|
#if VERSION_DICTIONARY
|
||||||
mVersion = mDictionary.mVersion;
|
mVersion = mDictionary.mVersion;
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue