Commit cce8439f authored by Clemens Hammacher's avatar Clemens Hammacher Committed by Commit Bot

Remove sorting methods from Vector

Instead, use std::sort and std::stable_sort at the 3 (!) call sites
directly. This also removes the weird comparer adaptors from Vector,
which are only used in ZoneList.

R=jkummerow@chromium.org

Bug: v8:9183
Change-Id: I4d0377976fb0a965cb68a21d4307df9ba09fd55d
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1587394Reviewed-by: 's avatarJakob Kummerow <jkummerow@chromium.org>
Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#61109}
parent 9c938706
......@@ -81,32 +81,6 @@ class Vector {
return Vector<T>(result, length_);
}
template <typename CompareFunction>
void Sort(CompareFunction cmp, size_t s, size_t l) {
std::sort(begin() + s, begin() + s + l, RawComparer<CompareFunction>(cmp));
}
template <typename CompareFunction>
void Sort(CompareFunction cmp) {
std::sort(begin(), begin() + length(), RawComparer<CompareFunction>(cmp));
}
void Sort() { std::sort(begin(), begin() + length()); }
template <typename CompareFunction>
void StableSort(CompareFunction cmp, size_t s, size_t l) {
std::stable_sort(begin() + s, begin() + s + l,
RawComparer<CompareFunction>(cmp));
}
template <typename CompareFunction>
void StableSort(CompareFunction cmp) {
std::stable_sort(begin(), begin() + length(),
RawComparer<CompareFunction>(cmp));
}
void StableSort() { std::stable_sort(begin(), begin() + length()); }
void Truncate(size_t length) {
DCHECK(length <= length_);
length_ = length;
......@@ -157,18 +131,6 @@ class Vector {
private:
T* start_;
size_t length_;
template <typename CookedComparer>
class RawComparer {
public:
explicit RawComparer(CookedComparer cmp) : cmp_(cmp) {}
bool operator()(const T& a, const T& b) {
return cmp_(&a, &b) < 0;
}
private:
CookedComparer cmp_;
};
};
......
......@@ -133,7 +133,8 @@ void ZoneList<T>::Iterate(Visitor* visitor) {
template <typename T>
template <typename CompareFunction>
void ZoneList<T>::Sort(CompareFunction cmp) {
ToVector().Sort(cmp, 0, length_);
std::sort(begin(), end(),
[cmp](const T& a, const T& b) { return cmp(&a, &b) < 0; });
#ifdef DEBUG
for (int i = 1; i < length_; i++) {
DCHECK_LE(cmp(&data_[i - 1], &data_[i]), 0);
......@@ -144,7 +145,8 @@ void ZoneList<T>::Sort(CompareFunction cmp) {
template <typename T>
template <typename CompareFunction>
void ZoneList<T>::StableSort(CompareFunction cmp, size_t s, size_t l) {
ToVector().StableSort(cmp, s, l);
std::stable_sort(begin() + s, begin() + s + l,
[cmp](const T& a, const T& b) { return cmp(&a, &b) < 0; });
#ifdef DEBUG
for (size_t i = s + 1; i < l; i++) {
DCHECK_LE(cmp(&data_[i - 1], &data_[i]), 0);
......
......@@ -674,7 +674,7 @@ TEST(DispatchTableConstruction) {
for (int j = 0; j < 2 * kRangeSize; j++) {
range[j] = PseudoRandom(i + 25, j + 87) % kLimit;
}
range.Sort();
std::sort(range.begin(), range.end());
for (int j = 1; j < 2 * kRangeSize; j++) {
CHECK(range[j-1] <= range[j]);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment