crlib: reduce hashmap memory usage.
build: fixed clang build.
This commit is contained in:
parent
17b9200195
commit
d40aab2b40
3 changed files with 14 additions and 7 deletions
|
|
@ -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_);
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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'
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue