]> granicus.if.org Git - clang/commitdiff
Cleanup/comment IdentifierInfo::get.
authorDaniel Dunbar <daniel@zuster.org>
Sat, 7 Mar 2009 01:42:16 +0000 (01:42 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Sat, 7 Mar 2009 01:42:16 +0000 (01:42 +0000)
 - Shaves off a few instructions on x86_64.

One notable change: this intentionally stops setting the II->Entry
field of IdentifierInfo's retrieved by the ExternalLookup method. This
is to maintain the invariant that .getName() has a constant value for
any given IdentifierInfo. IRgen currently relies on this; which is
quite questionable but will be cleaned up in time.

Apologies for the lack of a test case; there really isn't a good way
to make one. As IRgen will eventually be fixed to not rely on this, we
can survive without one.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@66316 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/IdentifierTable.h

index b6cee028f469b97c8cfb688a68105bf5dd906463..93651d3d91abd970a0ffd5074f7c95bdaf7c452b 100644 (file)
@@ -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<IdentifierInfo>();
-        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<IdentifierInfo>();
+    II = new (Mem) IdentifierInfo();
+    Entry.setValue(II);
+
+    // Make sure getName() knows how to find the IdentifierInfo
+    // contents.
+    II->Entry = &Entry;
+
     return *II;
   }