1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-23 19:23:23 +01:00

[IndexedAccessorRange] Only offset the base if the index is non-zero.

This is more efficient and removes the need for derived ranges to handle the degenerate empty case.
This commit is contained in:
River Riddle 2020-05-01 11:56:21 -07:00
parent 82c48a86e1
commit 42b872688a

View File

@ -1108,7 +1108,7 @@ public:
};
indexed_accessor_range_base(iterator begin, iterator end)
: base(DerivedT::offset_base(begin.getBase(), begin.getIndex())),
: base(offset_base(begin.getBase(), begin.getIndex())),
count(end.getIndex() - begin.getIndex()) {}
indexed_accessor_range_base(const iterator_range<iterator> &range)
: indexed_accessor_range_base(range.begin(), range.end()) {}
@ -1141,7 +1141,7 @@ public:
/// Drop the first N elements, and keep M elements.
DerivedT slice(size_t n, size_t m) const {
assert(n + m <= size() && "invalid size specifiers");
return DerivedT(DerivedT::offset_base(base, n), m);
return DerivedT(offset_base(base, n), m);
}
/// Drop the first n elements.
@ -1174,6 +1174,12 @@ public:
return RangeT(iterator_range<iterator>(*this));
}
private:
/// Offset the given base by the given amount.
static BaseT offset_base(const BaseT &base, size_t n) {
return n == 0 ? base : DerivedT::offset_base(base, n);
}
protected:
indexed_accessor_range_base(const indexed_accessor_range_base &) = default;
indexed_accessor_range_base(indexed_accessor_range_base &&) = default;