]> granicus.if.org Git - clang/commitdiff
Use a ContinuousRangeMap to map from the global selector ID in the AST
authorDouglas Gregor <dgregor@apple.com>
Wed, 20 Jul 2011 01:10:58 +0000 (01:10 +0000)
committerDouglas Gregor <dgregor@apple.com>
Wed, 20 Jul 2011 01:10:58 +0000 (01:10 +0000)
reader down to the AST file + local ID, rather than walking the PCH
chain. No functionality change; this is generalization and cleanup.

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

include/clang/Serialization/ASTReader.h
lib/Serialization/ASTReader.cpp

index 418925fce2e29abf670348075d5c3da34aa30e88..72bfb0f8a4ecd26f5aa4d5ea7e96546ff3a300ed 100644 (file)
@@ -570,6 +570,15 @@ private:
   /// been loaded.
   llvm::SmallVector<Selector, 16> SelectorsLoaded;
 
+  typedef ContinuousRangeMap<serialization::SelectorID, 
+                             std::pair<PerFileData *, int32_t>, 4> 
+    GlobalSelectorMapType;
+  
+  /// \brief Mapping from global selector IDs to the module in which the
+  /// selector resides along with the offset that should be added to the
+  /// global selector ID to produce a local ID.
+  GlobalSelectorMapType GlobalSelectorMap;
+
   /// \brief The macro definitions we have already loaded.
   llvm::SmallVector<MacroDefinition *, 16> MacroDefinitionsLoaded;
 
index 7d031019acb654035bd59d6520f11519b165e38a..3bb91770116d021ce75cc509dd6d4382f814b5ad 100644 (file)
@@ -2188,6 +2188,14 @@ ASTReader::ReadASTBlock(PerFileData &F) {
     case SELECTOR_OFFSETS:
       F.SelectorOffsets = (const uint32_t *)BlobStart;
       F.LocalNumSelectors = Record[0];
+        
+      // Introduce the global -> local mapping for identifiers within this AST
+      // file
+      GlobalSelectorMap.insert(
+                     std::make_pair(getTotalNumSelectors() + 1, 
+                                    std::make_pair(&F, 
+                                                   -getTotalNumSelectors())));
+      SelectorsLoaded.resize(SelectorsLoaded.size() + F.LocalNumSelectors);        
       break;
 
     case METHOD_POOL:
@@ -2538,15 +2546,13 @@ ASTReader::ASTReadResult ASTReader::ReadAST(const std::string &FileName,
 
   // Allocate space for loaded slocentries, identifiers, decls and types.
   unsigned TotalNumTypes = 0, 
-           TotalNumPreallocatedPreprocessingEntities = 0, TotalNumMacroDefs = 0,
-           TotalNumSelectors = 0;
+           TotalNumPreallocatedPreprocessingEntities = 0, TotalNumMacroDefs = 0;
   for (unsigned I = 0, N = Chain.size(); I != N; ++I) {
     TotalNumSLocEntries += Chain[I]->LocalNumSLocEntries;
     TotalNumTypes += Chain[I]->LocalNumTypes;
     TotalNumPreallocatedPreprocessingEntities +=
         Chain[I]->NumPreallocatedPreprocessingEntities;
     TotalNumMacroDefs += Chain[I]->LocalNumMacroDefinitions;
-    TotalNumSelectors += Chain[I]->LocalNumSelectors;
   }
   TypesLoaded.resize(TotalNumTypes);
   MacroDefinitionsLoaded.resize(TotalNumMacroDefs);
@@ -2559,7 +2565,6 @@ ASTReader::ASTReadResult ASTReader::ReadAST(const std::string &FileName,
                                      TotalNumPreallocatedPreprocessingEntities);
     }
   }
-  SelectorsLoaded.resize(TotalNumSelectors);
   // Preload SLocEntries.
   for (unsigned I = 0, N = PreloadSLocEntries.size(); I != N; ++I) {
     ASTReadResult Result = ReadSLocEntryRecord(PreloadSLocEntries[I]);
@@ -4645,19 +4650,15 @@ Selector ASTReader::DecodeSelector(unsigned ID) {
 
   if (SelectorsLoaded[ID - 1].getAsOpaquePtr() == 0) {
     // Load this selector from the selector table.
-    unsigned Idx = ID - 1;
-    for (unsigned I = 0, N = Chain.size(); I != N; ++I) {
-      PerFileData &F = *Chain[N - I - 1];
-      if (Idx < F.LocalNumSelectors) {
-        ASTSelectorLookupTrait Trait(*this);
-        SelectorsLoaded[ID - 1] =
-           Trait.ReadKey(F.SelectorLookupTableData + F.SelectorOffsets[Idx], 0);
-        if (DeserializationListener)
-          DeserializationListener->SelectorRead(ID, SelectorsLoaded[ID - 1]);
-        break;
-      }
-      Idx -= F.LocalNumSelectors;
-    }
+    GlobalSelectorMapType::iterator I = GlobalSelectorMap.find(ID);
+    assert(I != GlobalSelectorMap.end() && "Corrupted global selector map");
+    ASTSelectorLookupTrait Trait(*this);
+    PerFileData &F = *I->second.first;
+    unsigned Idx = ID - 1 + I->second.second;
+    SelectorsLoaded[ID - 1] =
+      Trait.ReadKey(F.SelectorLookupTableData + F.SelectorOffsets[Idx], 0);
+    if (DeserializationListener)
+      DeserializationListener->SelectorRead(ID, SelectorsLoaded[ID - 1]);
   }
 
   return SelectorsLoaded[ID - 1];