From 00e1dba744dc8d09bc59d0a46f18076e3704c566 Mon Sep 17 00:00:00 2001 From: jsmall-nvidia Date: Thu, 2 Apr 2020 17:06:16 -0400 Subject: 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 --- source/slang/slang-lookup.cpp | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) (limited to 'source/slang/slang-lookup.cpp') 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(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()) { 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); } -- cgit v1.2.3