r191173 - Rewrite a cold use of std::sort to array_pod_sort.

Benjamin Kramer benny.kra at googlemail.com
Sun Sep 22 05:41:24 PDT 2013


Author: d0k
Date: Sun Sep 22 07:41:24 2013
New Revision: 191173

URL: http://llvm.org/viewvc/llvm-project?rev=191173&view=rev
Log:
Rewrite a cold use of std::sort to array_pod_sort.

No functionality change.

Modified:
    cfe/trunk/lib/StaticAnalyzer/Checkers/DebugCheckers.cpp

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/DebugCheckers.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/DebugCheckers.cpp?rev=191173&r1=191172&r2=191173&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Checkers/DebugCheckers.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/DebugCheckers.cpp Sun Sep 22 07:41:24 2013
@@ -154,25 +154,29 @@ void ento::registerCallGraphDumper(Check
 
 namespace {
 class ConfigDumper : public Checker< check::EndOfTranslationUnit > {
+  typedef AnalyzerOptions::ConfigTable Table;
+
+  static int compareEntry(const void *LHS, const void *RHS) {
+    return ((const Table::MapEntryTy *)LHS)->getKey().compare(
+           ((const Table::MapEntryTy *)RHS)->getKey());
+  }
+
 public:
   void checkEndOfTranslationUnit(const TranslationUnitDecl *TU,
                                  AnalysisManager& mgr,
                                  BugReporter &BR) const {
+    const Table &Config = mgr.options.Config;
+
+    SmallVector<const Table::MapEntryTy *, 32> Keys;
+    for (Table::const_iterator I = Config.begin(), E = Config.end(); I != E;
+         ++I)
+      Keys.push_back(&*I);
+    llvm::array_pod_sort(Keys.begin(), Keys.end(), compareEntry);
 
-    const AnalyzerOptions::ConfigTable &Config = mgr.options.Config;
-    AnalyzerOptions::ConfigTable::const_iterator I =
-      Config.begin(), E = Config.end();
-
-    std::vector<StringRef> Keys;
-    for (; I != E ; ++I) { Keys.push_back(I->getKey()); }
-    sort(Keys.begin(), Keys.end());
-    
     llvm::errs() << "[config]\n";
-    for (unsigned i = 0, n = Keys.size(); i < n ; ++i) {
-      StringRef Key = Keys[i];
-      I = Config.find(Key);
-      llvm::errs() << Key << " = " << I->second << '\n';
-    }
+    for (unsigned I = 0, E = Keys.size(); I != E; ++I)
+      llvm::errs() << Keys[I]->getKey() << " = " << Keys[I]->second << '\n';
+
     llvm::errs() << "[stats]\n" << "num-entries = " << Keys.size() << '\n';
   }
 };





More information about the cfe-commits mailing list