]> granicus.if.org Git - clang/commitdiff
[Modules] Use global index to improve typo correction performance
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Wed, 17 Apr 2013 22:10:55 +0000 (22:10 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Wed, 17 Apr 2013 22:10:55 +0000 (22:10 +0000)
Typo correction for an unqualified name needs to walk through all of the identifier tables of all modules.
When we have a global index, just walk its identifier table only.

rdar://13425732

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

include/clang/Basic/IdentifierTable.h
include/clang/Serialization/ASTReader.h
include/clang/Serialization/GlobalModuleIndex.h
lib/Basic/IdentifierTable.cpp
lib/Serialization/ASTReader.cpp
lib/Serialization/GlobalModuleIndex.cpp

index c04a893c6f6e7a5006e14b173a7b64fb585842fd..d4d53390bdb334913466895c88e25e35e89a4aa5 100644 (file)
@@ -394,7 +394,7 @@ public:
   ///
   /// \returns A new iterator into the set of known identifiers. The
   /// caller is responsible for deleting this iterator.
-  virtual IdentifierIterator *getIdentifiers() const;
+  virtual IdentifierIterator *getIdentifiers();
 };
 
 /// \brief An abstract class used to resolve numerical identifier
index 925533678c15b42ecd5789b879c2ab995c370cc1..a773e416670ad96bd544c94170db4593ec81c215 100644 (file)
@@ -1558,7 +1558,7 @@ public:
 
   /// \brief Retrieve an iterator into the set of all identifiers
   /// in all loaded AST files.
-  virtual IdentifierIterator *getIdentifiers() const;
+  virtual IdentifierIterator *getIdentifiers();
 
   /// \brief Load the contents of the global method pool for a given
   /// selector.
index eaf26d1df16f6bb0f8526680f7007c6e395b3578..ab91f4009c0b08c958feb7474c5be34d2f456922 100644 (file)
@@ -146,6 +146,11 @@ public:
   static std::pair<GlobalModuleIndex *, ErrorCode>
   readIndex(StringRef Path);
 
+  /// \brief Returns an iterator for identifiers stored in the index table.
+  ///
+  /// The caller accepts ownership of the returned object.
+  IdentifierIterator *createIdentifierIterator() const;
+
   /// \brief Retrieve the set of modules that have up-to-date indexes.
   ///
   /// \param ModuleFiles Will be populated with the set of module files that
index 429d9d8cb21e3ba92f0dbf536ccb771c640eb409..951c718d183a9bdb50dd2a3aa512e22e3b070201 100644 (file)
@@ -65,7 +65,7 @@ namespace {
   };
 }
 
-IdentifierIterator *IdentifierInfoLookup::getIdentifiers() const {
+IdentifierIterator *IdentifierInfoLookup::getIdentifiers() {
   return new EmptyLookupIterator();
 }
 
index 9893823a122a11912aa7e46dc7a1d73de435ad1c..5123b79d2e94cb8a5a2f1110a49d22582deae92e 100644 (file)
@@ -6109,7 +6109,10 @@ StringRef ASTIdentifierIterator::Next() {
   return Result;
 }
 
-IdentifierIterator *ASTReader::getIdentifiers() const {
+IdentifierIterator *ASTReader::getIdentifiers() {
+  if (!loadGlobalIndex())
+    return GlobalIndex->createIdentifierIterator();
+
   return new ASTIdentifierIterator(*this);
 }
 
index f9acb847284d2819d7e29a94d8a89b8196354bae..b6693e40e51e1648ccc0530955c063503d592177 100644 (file)
@@ -818,3 +818,34 @@ GlobalModuleIndex::writeIndex(FileManager &FileMgr, StringRef Path) {
   // We're done.
   return EC_None;
 }
+
+namespace {
+  class GlobalIndexIdentifierIterator : public IdentifierIterator {
+    /// \brief The current position within the identifier lookup table.
+    IdentifierIndexTable::key_iterator Current;
+
+    /// \brief The end position within the identifier lookup table.
+    IdentifierIndexTable::key_iterator End;
+
+  public:
+    explicit GlobalIndexIdentifierIterator(IdentifierIndexTable &Idx) {
+      Current = Idx.key_begin();
+      End = Idx.key_end();
+    }
+
+    virtual StringRef Next() {
+      if (Current == End)
+        return StringRef();
+
+      StringRef Result = *Current;
+      ++Current;
+      return Result;
+    }
+  };
+}
+
+IdentifierIterator *GlobalModuleIndex::createIdentifierIterator() const {
+  IdentifierIndexTable &Table =
+    *static_cast<IdentifierIndexTable *>(IdentifierIndex);
+  return new GlobalIndexIdentifierIterator(Table);
+}