[PATCH] D14786: [llvm-profdata] Add merge() to InstrProfRecord

David Li via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 18 16:58:41 PST 2015


davidxl added inline comments.

================
Comment at: lib/ProfileData/InstrProfWriter.cpp:104
@@ -129,10 +103,3 @@
 
-  auto Where = ProfileDataMap.find(I.Hash);
-  if (Where == ProfileDataMap.end()) {
-    // We've never seen a function with this name and hash, add it.
-    ProfileDataMap[I.Hash] = I;
-
-    // We keep track of the max function count as we go for simplicity.
-    if (I.Counts[0] > MaxFunctionCount)
-      MaxFunctionCount = I.Counts[0];
-    return instrprof_error::success;
+  auto InsertResult = ProfileDataMap.insert(std::make_pair(I.Hash, I));
+  InstrProfRecord &Dest = InsertResult.first->second;
----------------
use std:make_pair(I.hash, InstrProfRecord()) to avoid side effect of making copies.

================
Comment at: lib/ProfileData/InstrProfWriter.cpp:111
@@ -139,1 +110,3 @@
+      return MergeResult;
+    }
   }
----------------
else {
   Dest = std::forward<InstrProfRecord>(I);
}

the std::forward is missing in the old code too which is less efficient.


http://reviews.llvm.org/D14786





More information about the llvm-commits mailing list