From 3f2eab52065661e3c941263e7a6424708e2d01e8 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Thu, 20 Feb 2025 17:04:20 +0100 Subject: [PATCH] Optimize divide into multiply --- Source/Engine/Core/Collections/Dictionary.h | 4 ++-- Source/Engine/Core/Collections/HashSet.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Source/Engine/Core/Collections/Dictionary.h b/Source/Engine/Core/Collections/Dictionary.h index efb7bafcf..d6af5f59d 100644 --- a/Source/Engine/Core/Collections/Dictionary.h +++ b/Source/Engine/Core/Collections/Dictionary.h @@ -403,7 +403,7 @@ public: ValueType& At(const KeyComparableType& key) { // Check if need to rehash elements (prevent many deleted elements that use too much of capacity) - if (_deletedCount > _size / DICTIONARY_DEFAULT_SLACK_SCALE) + if (_deletedCount * DICTIONARY_DEFAULT_SLACK_SCALE > _size) Compact(); // Ensure to have enough memory for the next item (in case of new element insertion) @@ -935,7 +935,7 @@ private: Bucket* OnAdd(const KeyComparableType& key) { // Check if need to rehash elements (prevent many deleted elements that use too much of capacity) - if (_deletedCount > _size / DICTIONARY_DEFAULT_SLACK_SCALE) + if (_deletedCount * DICTIONARY_DEFAULT_SLACK_SCALE > _size) Compact(); // Ensure to have enough memory for the next item (in case of new element insertion) diff --git a/Source/Engine/Core/Collections/HashSet.h b/Source/Engine/Core/Collections/HashSet.h index aa61354fd..f0e80c04f 100644 --- a/Source/Engine/Core/Collections/HashSet.h +++ b/Source/Engine/Core/Collections/HashSet.h @@ -730,7 +730,7 @@ private: Bucket* OnAdd(const ItemType& key) { // Check if need to rehash elements (prevent many deleted elements that use too much of capacity) - if (_deletedCount > _size / DICTIONARY_DEFAULT_SLACK_SCALE) + if (_deletedCount * DICTIONARY_DEFAULT_SLACK_SCALE > _size) Compact(); // Ensure to have enough memory for the next item (in case of new element insertion)