[DebugInfo] Simplify GSYM::AddressRange and GSYM::AddressRanges
Delete unnecessary getters of AddressRange.
Simplify AddressRange::size(): Start <= End check should be checked in an upper layer.
Delete isContiguousWith() that doesn't make sense.
Simplify AddressRanges::insert. Delete commented code. Fix it when more than 1 ranges are to be deleted.
Delete trailing newline.
llvm-svn: 364637
diff --git a/llvm/lib/DebugInfo/GSYM/Range.cpp b/llvm/lib/DebugInfo/GSYM/Range.cpp
index 57e664d..ca61984 100644
--- a/llvm/lib/DebugInfo/GSYM/Range.cpp
+++ b/llvm/lib/DebugInfo/GSYM/Range.cpp
@@ -15,53 +15,41 @@
using namespace gsym;
-void AddressRanges::insert(const AddressRange &Range) {
+void AddressRanges::insert(AddressRange Range) {
if (Range.size() == 0)
return;
- // Ranges.insert(std::upper_bound(Ranges.begin(), Ranges.end(), Range), Range);
- // // Check if an existing range intersects with this range, and if so,
- // // grow the intersecting ranges instead of adding a new one.
- auto Begin = Ranges.begin();
- auto End = Ranges.end();
- const auto Iter = std::upper_bound(Begin, End, Range);
- if (Iter != Begin) {
- auto PrevIter = Iter - 1;
- // If the previous range itersects with "Range" they will be combined.
- if (PrevIter->intersect(Range)) {
- // Now check if the previous range intersects with the next range since
- // the previous range was combined. If so, combine them and remove the
- // next range.
- if (Iter != End && PrevIter->intersect(*Iter))
- Ranges.erase(Iter);
- return;
- }
+ auto It = llvm::upper_bound(Ranges, Range);
+ auto It2 = It;
+ while (It2 != Ranges.end() && It2->Start < Range.End)
+ ++It2;
+ if (It != It2) {
+ Range.End = std::max(Range.End, It2[-1].End);
+ It = Ranges.erase(It, It2);
}
- // If the next range intersects with "Range", combined and return.
- if (Iter != End && Iter->intersect(Range))
- return;
- Ranges.insert(Iter, Range);
+ if (It != Ranges.begin() && Range.Start < It[-1].End)
+ It[-1].End = std::max(It[-1].End, Range.End);
+ else
+ Ranges.insert(It, Range);
}
bool AddressRanges::contains(uint64_t Addr) const {
auto It = std::partition_point(
Ranges.begin(), Ranges.end(),
- [=](const AddressRange &R) { return R.startAddress() <= Addr; });
- return It != Ranges.begin() && It[-1].contains(Addr);
+ [=](const AddressRange &R) { return R.Start <= Addr; });
+ return It != Ranges.begin() && Addr < It[-1].End;
}
raw_ostream &llvm::gsym::operator<<(raw_ostream &OS, const AddressRange &R) {
- return OS << '[' << HEX64(R.startAddress()) << " - " << HEX64(R.endAddress())
- << ")";
+ return OS << '[' << HEX64(R.Start) << " - " << HEX64(R.End) << ")";
}
raw_ostream &llvm::gsym::operator<<(raw_ostream &OS, const AddressRanges &AR) {
size_t Size = AR.size();
- for (size_t I=0; I<Size; ++I) {
+ for (size_t I = 0; I < Size; ++I) {
if (I)
OS << ' ';
OS << AR[I];
}
return OS;
}
-