[PATCH] D24034: [Coverage] Make sorting criteria for CounterMappingRegions local.
Igor Kudrin via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 30 09:04:04 PDT 2016
ikudrin created this revision.
ikudrin added reviewers: vsk, bogner.
ikudrin added a subscriber: llvm-commits.
Move the comparison function into the only place there it is used,
i.e. the call to std::stable_sort in CoverageMappingWriter::write().
Add sorting by region kinds as it is required to ensure stable order
in our tests and to simplify D23987.
https://reviews.llvm.org/D24034
Files:
include/llvm/ProfileData/Coverage/CoverageMapping.h
lib/ProfileData/Coverage/CoverageMappingWriter.cpp
Index: lib/ProfileData/Coverage/CoverageMappingWriter.cpp
===================================================================
--- lib/ProfileData/Coverage/CoverageMappingWriter.cpp
+++ lib/ProfileData/Coverage/CoverageMappingWriter.cpp
@@ -108,8 +108,16 @@
void CoverageMappingWriter::write(raw_ostream &OS) {
// Sort the regions in an ascending order by the file id and the starting
- // location.
- std::stable_sort(MappingRegions.begin(), MappingRegions.end());
+ // location. Sort by region kinds to ensure stable order for tests.
+ std::stable_sort(
+ MappingRegions.begin(), MappingRegions.end(),
+ [](const CounterMappingRegion &LHS, const CounterMappingRegion &RHS) {
+ if (LHS.FileID != RHS.FileID)
+ return LHS.FileID < RHS.FileID;
+ if (LHS.startLoc() != RHS.startLoc())
+ return LHS.startLoc() < RHS.startLoc();
+ return LHS.Kind < RHS.Kind;
+ });
// Write out the fileid -> filename mapping.
encodeULEB128(VirtualFileMapping.size(), OS);
Index: include/llvm/ProfileData/Coverage/CoverageMapping.h
===================================================================
--- include/llvm/ProfileData/Coverage/CoverageMapping.h
+++ include/llvm/ProfileData/Coverage/CoverageMapping.h
@@ -245,12 +245,6 @@
return std::pair<unsigned, unsigned>(LineEnd, ColumnEnd);
}
- bool operator<(const CounterMappingRegion &Other) const {
- if (FileID != Other.FileID)
- return FileID < Other.FileID;
- return startLoc() < Other.startLoc();
- }
-
bool contains(const CounterMappingRegion &Other) const {
if (FileID != Other.FileID)
return false;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D24034.69703.patch
Type: text/x-patch
Size: 1648 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160830/47336e69/attachment.bin>
More information about the llvm-commits
mailing list