summaryrefslogtreecommitdiff
path: root/source/core/slang-dictionary.h
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2023-07-18 08:08:11 -0700
committerGitHub <noreply@github.com>2023-07-18 15:08:11 +0000
commit4cb3eeb832b5fb29a61f2934b3daa5e42a3d6cde (patch)
tree89713b5d83b4fee0dad6aa52b72d5ca695f4e8f1 /source/core/slang-dictionary.h
parent138a44ef272841cb555fa0eb5c49cc889bf1d64a (diff)
Simplify Lookup and improve compiler performance. (#2996)
* Simplify lookup. * Various bug fixes. * Report type dictionary size in perf benchmark. * Remove type duplication. * increase initial dict size. * Bug fix. * Fix bugs. * Fixup. * Revert type legalization looping. * Fix specialization pass. --------- Co-authored-by: Yong He <yhe@nvidia.com>
Diffstat (limited to 'source/core/slang-dictionary.h')
-rw-r--r--source/core/slang-dictionary.h36
1 files changed, 22 insertions, 14 deletions
diff --git a/source/core/slang-dictionary.h b/source/core/slang-dictionary.h
index 0350a99d2..2c683abfe 100644
--- a/source/core/slang-dictionary.h
+++ b/source/core/slang-dictionary.h
@@ -191,20 +191,9 @@ namespace Slang
int newSize = (m_bucketCountMinusOne + 1) * 2;
if (newSize == 0)
{
- newSize = 16;
+ newSize = 64;
}
- Dictionary<TKey, TValue> newDict;
- newDict.m_bucketCountMinusOne = newSize - 1;
- newDict.m_hashMap = new KeyValuePair<TKey, TValue>[newSize];
- newDict.m_marks.resizeAndClear(newSize * 2);
- if (m_hashMap)
- {
- for (auto& kvPair : *this)
- {
- newDict.add(_Move(kvPair));
- }
- }
- *this = _Move(newDict);
+ reserve(newSize);
}
}
@@ -344,6 +333,25 @@ namespace Slang
m_marks.clear();
}
+ void reserve(int newSize)
+ {
+ if (newSize <= m_bucketCountMinusOne + 1)
+ return;
+
+ Dictionary<TKey, TValue> newDict;
+ newDict.m_bucketCountMinusOne = newSize - 1;
+ newDict.m_hashMap = new KeyValuePair<TKey, TValue>[newSize];
+ newDict.m_marks.resizeAndClear(newSize * 2);
+ if (m_hashMap)
+ {
+ for (auto& kvPair : *this)
+ {
+ newDict.add(_Move(kvPair));
+ }
+ }
+ *this = _Move(newDict);
+ }
+
TValue* tryGetValueOrAdd(const TKey& key, const TValue& value)
{
maybeRehash();
@@ -785,7 +793,7 @@ namespace Slang
int newSize = (m_bucketCountMinusOne + 1) * 2;
if (newSize == 0)
{
- newSize = 16;
+ newSize = 128;
}
OrderedDictionary<TKey, TValue> newDict;
newDict.m_bucketCountMinusOne = newSize - 1;