[cfe-commits] r66316 - /cfe/trunk/include/clang/Basic/IdentifierTable.h

Daniel Dunbar daniel at zuster.org
Fri Mar 6 17:42:16 PST 2009


Author: ddunbar
Date: Fri Mar  6 19:42:16 2009
New Revision: 66316

URL: http://llvm.org/viewvc/llvm-project?rev=66316&view=rev
Log:
Cleanup/comment IdentifierInfo::get.
 - 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.

Modified:
    cfe/trunk/include/clang/Basic/IdentifierTable.h

Modified: cfe/trunk/include/clang/Basic/IdentifierTable.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/IdentifierTable.h?rev=66316&r1=66315&r2=66316&view=diff

==============================================================================
--- cfe/trunk/include/clang/Basic/IdentifierTable.h (original)
+++ cfe/trunk/include/clang/Basic/IdentifierTable.h Fri Mar  6 19:42:16 2009
@@ -267,24 +267,27 @@
       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;
   }
   





More information about the cfe-commits mailing list