From: Justin Bogner Date: Thu, 18 Sep 2014 20:31:26 +0000 (+0000) Subject: llvm-cov: Simplify FunctionInstantiationSetCollector (NFC) X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=e3d674f88dbe6cd80ddd003c99ec4d6b512b2500;p=oota-llvm.git llvm-cov: Simplify FunctionInstantiationSetCollector (NFC) - Replace std::unordered_map with DenseMap - Use std::pair instead of manually combining two unsigneds - Assert if insert is called with invalid arguments - Avoid an unnecessary copy of a std::vector git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@218074 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/tools/llvm-cov/CodeCoverage.cpp b/tools/llvm-cov/CodeCoverage.cpp index 73ab317025c..82b1175a378 100644 --- a/tools/llvm-cov/CodeCoverage.cpp +++ b/tools/llvm-cov/CodeCoverage.cpp @@ -20,6 +20,7 @@ #include "SourceCoverageView.h" #include "CoverageSummary.h" #include "CoverageReport.h" +#include "llvm/ADT/DenseMap.h" #include "llvm/ADT/StringRef.h" #include "llvm/ADT/SmallString.h" #include "llvm/ADT/SmallSet.h" @@ -37,49 +38,35 @@ #include "llvm/Support/PrettyStackTrace.h" #include #include -#include using namespace llvm; using namespace coverage; namespace { /// \brief Distribute the functions into instantiation sets. -/// An instantiation set is a collection of functions -/// that have the same source code, e.g. -/// template functions specializations. +/// +/// An instantiation set is a collection of functions that have the same source +/// code, ie, template functions specializations. class FunctionInstantiationSetCollector { - ArrayRef FunctionMappings; - typedef uint64_t KeyType; - typedef std::vector SetType; - std::unordered_map InstantiatedFunctions; - - static KeyType getKey(const CountedRegion &R) { - return uint64_t(R.LineStart) | uint64_t(R.ColumnStart) << 32; - } + typedef DenseMap, + std::vector> MapT; + MapT InstantiatedFunctions; public: void insert(const FunctionCoverageMapping &Function, unsigned FileID) { - KeyType Key = 0; - for (const auto &R : Function.CountedRegions) { - if (R.FileID == FileID) { - Key = getKey(R); - break; - } - } - auto I = InstantiatedFunctions.find(Key); - if (I == InstantiatedFunctions.end()) { - SetType Set; - Set.push_back(&Function); - InstantiatedFunctions.insert(std::make_pair(Key, Set)); - } else - I->second.push_back(&Function); + auto I = Function.CountedRegions.begin(), E = Function.CountedRegions.end(); + while (I != E && I->FileID != FileID) + ++I; + assert(I != E && "function does not cover the given file"); + auto &Functions = InstantiatedFunctions[I->startLoc()]; + Functions.push_back(&Function); } - std::unordered_map::iterator begin() { + MapT::iterator begin() { return InstantiatedFunctions.begin(); } - std::unordered_map::iterator end() { + MapT::iterator end() { return InstantiatedFunctions.end(); } };