aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorRichard Smith <richard-llvm@metafoo.co.uk>2013-02-08 00:37:45 +0000
committerRichard Smith <richard-llvm@metafoo.co.uk>2013-02-08 00:37:45 +0000
commit2bb07c1dfeda50d7edcee512932b86a1a65c6e69 (patch)
treedbe3bfc7737c2f75676461415704be2a6a1734d8 /lib
parentada7191795dde85a620008094fbe5464abdb916b (diff)
Fix stack overflow and improve performance when a module contains many
overloads of a name by claiming that there are no lookup results for that name in modules while loading the names from the module. Lookups in deserialization really don't want to find names which they themselves are in the process of introducing. This also has the pleasant side-effect of automatically caching PCH lookups which found no names. The runtime here is still quadratic in the number of overloads, but the constant is lower. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@174685 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r--lib/AST/DeclBase.cpp12
1 files changed, 7 insertions, 5 deletions
diff --git a/lib/AST/DeclBase.cpp b/lib/AST/DeclBase.cpp
index 3039c95462..e1202c23a8 100644
--- a/lib/AST/DeclBase.cpp
+++ b/lib/AST/DeclBase.cpp
@@ -1203,14 +1203,16 @@ DeclContext::lookup(DeclarationName Name) {
if (LookupPtr.getInt())
Map = buildLookup();
+ if (!Map)
+ Map = CreateStoredDeclsMap(getParentASTContext());
+
// If a PCH/module has a result for this name, and we have a local
// declaration, we will have imported the PCH/module result when adding the
// local declaration or when reconciling the module.
- if (Map) {
- StoredDeclsMap::iterator I = Map->find(Name);
- if (I != Map->end())
- return I->second.getLookupResult();
- }
+ std::pair<StoredDeclsMap::iterator, bool> R =
+ Map->insert(std::make_pair(Name, StoredDeclsList()));
+ if (!R.second)
+ return R.first->second.getLookupResult();
ExternalASTSource *Source = getParentASTContext().getExternalSource();
if (Source->FindExternalVisibleDeclsByName(this, Name)) {