[PATCH] D116037: [clang-include-fixer] Fix incorrect ranking because of dangling references

Benjamin Kramer via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Dec 20 07:04:50 PST 2021


This revision was automatically updated to reflect the committed changes.
Closed by commit rGcff192739bb6: [clang-include-fixer] Fix incorrect ranking because of dangling references (authored by danlark, committed by bkramer).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D116037/new/

https://reviews.llvm.org/D116037

Files:
  clang-tools-extra/clang-include-fixer/SymbolIndexManager.cpp


Index: clang-tools-extra/clang-include-fixer/SymbolIndexManager.cpp
===================================================================
--- clang-tools-extra/clang-include-fixer/SymbolIndexManager.cpp
+++ clang-tools-extra/clang-include-fixer/SymbolIndexManager.cpp
@@ -8,8 +8,9 @@
 
 #include "SymbolIndexManager.h"
 #include "find-all-symbols/SymbolInfo.h"
-#include "llvm/ADT/DenseMap.h"
+#include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/StringMap.h"
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/Path.h"
 
@@ -47,7 +48,7 @@
 
 static void rank(std::vector<SymbolAndSignals> &Symbols,
                  llvm::StringRef FileName) {
-  llvm::DenseMap<llvm::StringRef, double> Score;
+  llvm::StringMap<double> Score;
   for (const auto &Symbol : Symbols) {
     // Calculate a score from the similarity of the header the symbol is in
     // with the current file and the popularity of the symbol.
@@ -58,14 +59,14 @@
   }
   // Sort by the gathered scores. Use file name as a tie breaker so we can
   // deduplicate.
-  std::sort(Symbols.begin(), Symbols.end(),
-            [&](const SymbolAndSignals &A, const SymbolAndSignals &B) {
-              auto AS = Score[A.Symbol.getFilePath()];
-              auto BS = Score[B.Symbol.getFilePath()];
-              if (AS != BS)
-                return AS > BS;
-              return A.Symbol.getFilePath() < B.Symbol.getFilePath();
-            });
+  llvm::sort(Symbols.begin(), Symbols.end(),
+             [&](const SymbolAndSignals &A, const SymbolAndSignals &B) {
+               auto AS = Score[A.Symbol.getFilePath()];
+               auto BS = Score[B.Symbol.getFilePath()];
+               if (AS != BS)
+                 return AS > BS;
+               return A.Symbol.getFilePath() < B.Symbol.getFilePath();
+             });
 }
 
 std::vector<find_all_symbols::SymbolInfo>


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D116037.395437.patch
Type: text/x-patch
Size: 1884 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20211220/8fcec39a/attachment.bin>


More information about the cfe-commits mailing list