diff options
| author | jsmall-nvidia <jsmall@nvidia.com> | 2020-04-02 17:06:16 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-04-02 17:06:16 -0400 |
| commit | 00e1dba744dc8d09bc59d0a46f18076e3704c566 (patch) | |
| tree | c22a1e0767af2bc46a351ba6b1bf9ee58d8b7791 /source/slang/slang-lookup.cpp | |
| parent | 487d4a4f406c9dd9803ecdca02467d09ee1ecf4a (diff) | |
Optimize creation of memberDictionary (#1305)
* Improve performance of building members dictionary by adding when needed.
* Fix unbounded-array-of-array-syntax.slang, that DISABLE_TEST now uses up an index. Use IGNORE_TEST.
* Improve variable name.
Small improvements.
Co-authored-by: Tim Foley <tfoleyNV@users.noreply.github.com>
Diffstat (limited to 'source/slang/slang-lookup.cpp')
| -rw-r--r-- | source/slang/slang-lookup.cpp | 31 |
1 files changed, 21 insertions, 10 deletions
diff --git a/source/slang/slang-lookup.cpp b/source/slang/slang-lookup.cpp index 6a2d31c32..5f2927ccb 100644 --- a/source/slang/slang-lookup.cpp +++ b/source/slang/slang-lookup.cpp @@ -30,24 +30,35 @@ struct BreadcrumbInfo void buildMemberDictionary(ContainerDecl* decl) { // Don't rebuild if already built - if (decl->memberDictionaryIsValid) + if (decl->isMemberDictionaryValid()) return; - decl->memberDictionary.Clear(); - decl->transparentMembers.clear(); + // If it's < 0 it means that the dictionaries are entirely invalid + if (decl->dictionaryLastCount < 0) + { + decl->dictionaryLastCount = 0; + decl->memberDictionary.Clear(); + decl->transparentMembers.clear(); + } // are we a generic? GenericDecl* genericDecl = as<GenericDecl>(decl); - for (auto m : decl->Members) + const Index membersCount = decl->Members.getCount(); + + SLANG_ASSERT(decl->dictionaryLastCount >= 0 && decl->dictionaryLastCount <= membersCount); + + for (Index i = decl->dictionaryLastCount; i < membersCount; ++i) { + Decl* m = decl->Members[i]; + auto name = m->getName(); // Add any transparent members to a separate list for lookup if (m->HasModifier<TransparentModifier>()) { TransparentMemberInfo info; - info.decl = m.Ptr(); + info.decl = m; decl->transparentMembers.add(info); } @@ -59,17 +70,17 @@ void buildMemberDictionary(ContainerDecl* decl) if (genericDecl && m == genericDecl->inner) continue; - m->nextInContainerWithSameName = nullptr; Decl* next = nullptr; if (decl->memberDictionary.TryGetValue(name, next)) m->nextInContainerWithSameName = next; - decl->memberDictionary[name] = m.Ptr(); - + decl->memberDictionary[name] = m; } - decl->memberDictionaryIsValid = true; + + decl->dictionaryLastCount = membersCount; + SLANG_ASSERT(decl->isMemberDictionaryValid()); } @@ -186,7 +197,7 @@ static void _lookUpDirectAndTransparentMembers( ContainerDecl* containerDecl = containerDeclRef.getDecl(); // Ensure that the lookup dictionary in the container is up to date - if (!containerDecl->memberDictionaryIsValid) + if (!containerDecl->isMemberDictionaryValid()) { buildMemberDictionary(containerDecl); } |
