ioeric updated this revision to Diff 59027.
ioeric added a comment.

- Removed a redundant set of symbols during merging.


http://reviews.llvm.org/D20804

Files:
  include-fixer/find-all-symbols/SymbolInfo.cpp
  include-fixer/find-all-symbols/SymbolInfo.h
  include-fixer/find-all-symbols/tool/FindAllSymbolsMain.cpp
  test/include-fixer/Inputs/fake_yaml_db.yaml

Index: test/include-fixer/Inputs/fake_yaml_db.yaml
===================================================================
--- test/include-fixer/Inputs/fake_yaml_db.yaml
+++ test/include-fixer/Inputs/fake_yaml_db.yaml
@@ -8,6 +8,7 @@
 FilePath:        foo.h
 LineNumber:      1
 Type:            Class
+NumOccurrences:  1
 ...
 ---
 Name:           bar
@@ -19,4 +20,5 @@
 FilePath:        ../include/bar.h
 LineNumber:      1
 Type:            Class
+NumOccurrences:  1
 ...
Index: include-fixer/find-all-symbols/tool/FindAllSymbolsMain.cpp
===================================================================
--- include-fixer/find-all-symbols/tool/FindAllSymbolsMain.cpp
+++ include-fixer/find-all-symbols/tool/FindAllSymbolsMain.cpp
@@ -87,12 +87,13 @@
 
 bool Merge(llvm::StringRef MergeDir, llvm::StringRef OutputFile) {
   std::error_code EC;
-  std::set<SymbolInfo> UniqueSymbols;
+  std::map<SymbolInfo, int> SymbolToNumOccurrences;
   std::mutex SymbolMutex;
   auto AddSymbols = [&](ArrayRef<SymbolInfo> Symbols) {
     // Synchronize set accesses.
     std::unique_lock<std::mutex> LockGuard(SymbolMutex);
-    UniqueSymbols.insert(Symbols.begin(), Symbols.end());
+    for (const auto &Symbol : Symbols)
+      ++SymbolToNumOccurrences[Symbol];
   };
 
   // Load all symbol files in MergeDir.
@@ -123,7 +124,14 @@
                  << '\n';
     return false;
   }
-  WriteSymbolInfosToStream(OS, UniqueSymbols);
+  std::set<SymbolInfo> Result;
+  for (const auto &Entry : SymbolToNumOccurrences) {
+    const auto &Symbol = Entry.first;
+    Result.insert(SymbolInfo(Symbol.getName(), Symbol.getSymbolKind(),
+                             Symbol.getFilePath(), Symbol.getLineNumber(),
+                             Symbol.getContexts(), Entry.second));
+  }
+  WriteSymbolInfosToStream(OS, Result);
   return true;
 }
 
Index: include-fixer/find-all-symbols/SymbolInfo.h
===================================================================
--- include-fixer/find-all-symbols/SymbolInfo.h
+++ include-fixer/find-all-symbols/SymbolInfo.h
@@ -51,7 +51,8 @@
   SymbolInfo() : Type(SymbolKind::Unknown), LineNumber(-1) {}
 
   SymbolInfo(llvm::StringRef Name, SymbolKind Type, llvm::StringRef FilePath,
-             int LineNumber, const std::vector<Context> &Contexts);
+             int LineNumber, const std::vector<Context> &Contexts,
+             unsigned NumOccurrences = 0);
 
   /// \brief Get symbol name.
   llvm::StringRef getName() const;
@@ -68,6 +69,9 @@
   /// \brief Get a 1-based line number of the symbol's declaration.
   int getLineNumber() const;
 
+  /// \brief The number of times this symbol was found during an indexing run.
+  unsigned getNumOccurrences() const;
+
   bool operator<(const SymbolInfo &Symbol) const;
 
   bool operator==(const SymbolInfo &Symbol) const;
@@ -99,6 +103,10 @@
 
   /// \brief The 1-based line number of of the symbol's declaration.
   int LineNumber;
+
+  /// \brief The number of times this symbol was found during an indexing
+  /// run. Populated by the reducer and used to rank results.
+  unsigned NumOccurrences;
 };
 
 /// \brief Write SymbolInfos to a stream (YAML format).
Index: include-fixer/find-all-symbols/SymbolInfo.cpp
===================================================================
--- include-fixer/find-all-symbols/SymbolInfo.cpp
+++ include-fixer/find-all-symbols/SymbolInfo.cpp
@@ -33,6 +33,7 @@
     io.mapRequired("FilePath", Symbol.FilePath);
     io.mapRequired("LineNumber", Symbol.LineNumber);
     io.mapRequired("Type", Symbol.Type);
+    io.mapRequired("NumOccurrences", Symbol.NumOccurrences);
   }
 };
 
@@ -72,9 +73,10 @@
 
 SymbolInfo::SymbolInfo(llvm::StringRef Name, SymbolKind Type,
                        llvm::StringRef FilePath, int LineNumber,
-                       const std::vector<Context> &Contexts)
+                       const std::vector<Context> &Contexts,
+                       unsigned NumOccurrences)
     : Name(Name), Type(Type), FilePath(FilePath), Contexts(Contexts),
-      LineNumber(LineNumber) {}
+      LineNumber(LineNumber), NumOccurrences(NumOccurrences) {}
 
 llvm::StringRef SymbolInfo::getName() const { return Name; }
 
@@ -88,6 +90,8 @@
 
 int SymbolInfo::getLineNumber() const { return LineNumber; }
 
+unsigned SymbolInfo::getNumOccurrences() const { return NumOccurrences; }
+
 bool SymbolInfo::operator==(const SymbolInfo &Symbol) const {
   return std::tie(Name, Type, FilePath, LineNumber, Contexts) ==
          std::tie(Symbol.Name, Symbol.Type, Symbol.FilePath, Symbol.LineNumber,
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to