crlib: reduce hashmap memory usage.

build: fixed clang build.
This commit is contained in:
ds 2020-11-08 11:41:41 +03:00
commit d40aab2b40
3 changed files with 14 additions and 7 deletions

View file

@ -103,8 +103,15 @@ private:
return hash_ (key) % length;
}
void rehash () {
auto capacity = (capacity_ << 1);
void rehash (size_t targetCapacity) {
if (length_ + targetCapacity < capacity_) {
return;
}
auto capacity = capacity_ ? capacity_ : 3;
while (length_ + targetCapacity > capacity) {
capacity *= 2;
}
auto contents = cr::makeUnique <Entries> (capacity);
for (size_t i = 0; i < capacity_; ++i) {
@ -188,7 +195,7 @@ public:
for (size_t i = 0; i < capacity_; ++i) {
contents_[i].used = false;
}
rehash ();
rehash (0);
}
void foreach (Lambda <void (const K &, const V &)> callback) {
@ -201,8 +208,8 @@ public:
public:
V &operator [] (const K &key) {
if ((length_ << 1) > capacity_) {
rehash ();
if (length_ >= capacity_) {
rehash (length_ << 1);
}
auto result = put (key, contents_, capacity_);

View file

@ -49,7 +49,7 @@ private:
StringArray m_logos;
StringArray m_avatars;
HashMap <uint32, String, Hash <int32>> m_language { 256 };
HashMap <uint32, String, Hash <int32>> m_language;
HashMap <int32, DifficultyData> m_difficulty;
// default tables for personality weapon preferences, overridden by weapon.cfg

View file

@ -95,11 +95,11 @@ if isCLang or isGCC or (isIntel and not isWindows)
if isGCC
flagsCompiler += '-fgraphite-identity'
flagsLinker += '-flto-partition=none'
endif
flagsLinker += [
'-flto',
'-flto-partition=none',
'-s',
'-Wl,--version-script=../version_script.lds',
'-Wl,--gc-sections'