Fix regression in Dictionary capacity and use similar improvement in HashSet
This commit is contained in:
@@ -407,7 +407,7 @@ public:
|
|||||||
Compact();
|
Compact();
|
||||||
|
|
||||||
// Ensure to have enough memory for the next item (in case of new element insertion)
|
// Ensure to have enough memory for the next item (in case of new element insertion)
|
||||||
EnsureCapacity(_elementsCount + 1 + _deletedCount);
|
EnsureCapacity(((_elementsCount + 1) * DICTIONARY_DEFAULT_SLACK_SCALE + _deletedCount) / DICTIONARY_DEFAULT_SLACK_SCALE);
|
||||||
|
|
||||||
// Find location of the item or place to insert it
|
// Find location of the item or place to insert it
|
||||||
FindPositionResult pos;
|
FindPositionResult pos;
|
||||||
@@ -940,7 +940,7 @@ private:
|
|||||||
Compact();
|
Compact();
|
||||||
|
|
||||||
// Ensure to have enough memory for the next item (in case of new element insertion)
|
// Ensure to have enough memory for the next item (in case of new element insertion)
|
||||||
EnsureCapacity(_elementsCount + 1 + _deletedCount);
|
EnsureCapacity(((_elementsCount + 1) * DICTIONARY_DEFAULT_SLACK_SCALE + _deletedCount) / DICTIONARY_DEFAULT_SLACK_SCALE);
|
||||||
|
|
||||||
// Find location of the item or place to insert it
|
// Find location of the item or place to insert it
|
||||||
FindPositionResult pos;
|
FindPositionResult pos;
|
||||||
|
|||||||
@@ -470,8 +470,9 @@ public:
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="minCapacity">The minimum required capacity.</param>
|
/// <param name="minCapacity">The minimum required capacity.</param>
|
||||||
/// <param name="preserveContents">True if preserve collection data when changing its size, otherwise collection after resize will be empty.</param>
|
/// <param name="preserveContents">True if preserve collection data when changing its size, otherwise collection after resize will be empty.</param>
|
||||||
void EnsureCapacity(const int32 minCapacity, const bool preserveContents = true)
|
void EnsureCapacity(int32 minCapacity, const bool preserveContents = true)
|
||||||
{
|
{
|
||||||
|
minCapacity *= DICTIONARY_DEFAULT_SLACK_SCALE;
|
||||||
if (_size >= minCapacity)
|
if (_size >= minCapacity)
|
||||||
return;
|
return;
|
||||||
int32 capacity = _allocation.CalculateCapacityGrow(_size, minCapacity);
|
int32 capacity = _allocation.CalculateCapacityGrow(_size, minCapacity);
|
||||||
@@ -734,7 +735,7 @@ private:
|
|||||||
Compact();
|
Compact();
|
||||||
|
|
||||||
// Ensure to have enough memory for the next item (in case of new element insertion)
|
// Ensure to have enough memory for the next item (in case of new element insertion)
|
||||||
EnsureCapacity((_elementsCount + 1) * DICTIONARY_DEFAULT_SLACK_SCALE + _deletedCount);
|
EnsureCapacity(((_elementsCount + 1) * DICTIONARY_DEFAULT_SLACK_SCALE + _deletedCount) / DICTIONARY_DEFAULT_SLACK_SCALE);
|
||||||
|
|
||||||
// Find location of the item or place to insert it
|
// Find location of the item or place to insert it
|
||||||
FindPositionResult pos;
|
FindPositionResult pos;
|
||||||
|
|||||||
Reference in New Issue
Block a user