From: Daniel Dunbar Date: Mon, 9 Mar 2009 23:43:07 +0000 (+0000) Subject: Reapply r66316, it got accidentally reverted in r66317. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d43b333be82438102ff4c459b1fb5dfb764e5f0d;p=clang Reapply r66316, it got accidentally reverted in r66317. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@66506 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Basic/IdentifierTable.h b/include/clang/Basic/IdentifierTable.h index 7630811f21..df0200f1e7 100644 --- a/include/clang/Basic/IdentifierTable.h +++ b/include/clang/Basic/IdentifierTable.h @@ -267,24 +267,27 @@ public: HashTable.GetOrCreateValue(NameStart, NameEnd); IdentifierInfo *II = Entry.getValue(); + if (II) return *II; - if (!II) { - while (1) { - if (ExternalLookup) { - II = ExternalLookup->get(NameStart, NameEnd); - if (II) break; - } - - void *Mem = getAllocator().Allocate(); - II = new (Mem) IdentifierInfo(); - break; + // No entry; if we have an external lookup, look there first. + if (ExternalLookup) { + II = ExternalLookup->get(NameStart, NameEnd); + if (II) { + // Cache in the StringMap for subsequent lookups. + Entry.setValue(II); + return *II; } - - Entry.setValue(II); - II->Entry = &Entry; } - assert(II->Entry != 0); + // Lookups failed, make a new IdentifierInfo. + void *Mem = getAllocator().Allocate(); + II = new (Mem) IdentifierInfo(); + Entry.setValue(II); + + // Make sure getName() knows how to find the IdentifierInfo + // contents. + II->Entry = &Entry; + return *II; }