diff --git a/Source/Engine/Core/Collections/Dictionary.h b/Source/Engine/Core/Collections/Dictionary.h
index 90c87d8e8..01b33cf2d 100644
--- a/Source/Engine/Core/Collections/Dictionary.h
+++ b/Source/Engine/Core/Collections/Dictionary.h
@@ -407,7 +407,7 @@ public:
Compact();
// 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
FindPositionResult pos;
@@ -940,7 +940,7 @@ private:
Compact();
// 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
FindPositionResult pos;
diff --git a/Source/Engine/Core/Collections/HashSet.h b/Source/Engine/Core/Collections/HashSet.h
index aa61354fd..838db7a35 100644
--- a/Source/Engine/Core/Collections/HashSet.h
+++ b/Source/Engine/Core/Collections/HashSet.h
@@ -470,8 +470,9 @@ public:
///
/// The minimum required capacity.
/// True if preserve collection data when changing its size, otherwise collection after resize will be empty.
- 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)
return;
int32 capacity = _allocation.CalculateCapacityGrow(_size, minCapacity);
@@ -734,7 +735,7 @@ private:
Compact();
// 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
FindPositionResult pos;