1 //===- SourceCoverageDataManager.cpp - Manager for source file coverage
4 // The LLVM Compiler Infrastructure
6 // This file is distributed under the University of Illinois Open Source
7 // License. See LICENSE.TXT for details.
9 //===----------------------------------------------------------------------===//
11 // This class separates and merges mapping regions for a specific source file.
13 //===----------------------------------------------------------------------===//
15 #include "SourceCoverageDataManager.h"
18 using namespace coverage;
20 void SourceCoverageDataManager::insert(const CountedRegion &CR) {
21 Regions.push_back(CR);
25 ArrayRef<CountedRegion> SourceCoverageDataManager::getSourceRegions() {
26 if (Uniqued || Regions.size() <= 1)
29 // Sort the regions given that they're all in the same file at this point.
30 std::sort(Regions.begin(), Regions.end(),
31 [](const CountedRegion &LHS, const CountedRegion &RHS) {
32 return LHS.startLoc() < RHS.startLoc();
35 // Merge duplicate source ranges and sum their execution counts.
36 auto Prev = Regions.begin();
37 for (auto I = Prev + 1, E = Regions.end(); I != E; ++I) {
38 if (I->startLoc() == Prev->startLoc() && I->endLoc() == Prev->endLoc()) {
39 Prev->ExecutionCount += I->ExecutionCount;
46 Regions.erase(Prev, Regions.end());