Bug 1012964 - IonMonkey: Optimize LiveInterval::addRange. r=bhackett

This commit is contained in:
Dan Gohman 2014-05-20 13:36:40 -07:00
parent d31ba5ed02
commit c7d6078a3a
2 changed files with 38 additions and 14 deletions

View File

@ -76,6 +76,7 @@ bool
LiveInterval::addRangeAtHead(CodePosition from, CodePosition to)
{
JS_ASSERT(from < to);
JS_ASSERT(ranges_.empty() || from <= ranges_.back().from);
Range newRange(from, to);
@ -110,23 +111,28 @@ LiveInterval::addRange(CodePosition from, CodePosition to)
Range *i;
// Find the location to insert the new range
for (i = ranges_.end() - 1; i >= ranges_.begin(); i--) {
if (newRange.from <= i->to) {
if (i->from < newRange.from)
newRange.from = i->from;
for (i = ranges_.end(); i > ranges_.begin(); i--) {
if (newRange.from <= i[-1].to) {
if (i[-1].from < newRange.from)
newRange.from = i[-1].from;
break;
}
}
// Perform coalescing on overlapping ranges
for (; i >= ranges_.begin(); i--) {
if (newRange.to < i->from)
Range *j = i;
for (; i > ranges_.begin(); i--) {
if (newRange.to < i[-1].from)
break;
if (newRange.to < i->to)
newRange.to = i->to;
ranges_.erase(i);
if (newRange.to < i[-1].to)
newRange.to = i[-1].to;
}
return ranges_.insert(i + 1, newRange);
if (i == j)
return ranges_.insert(i, newRange);
i[0] = newRange;
ranges_.erase(i + 1, j);
return true;
}
void
@ -134,10 +140,10 @@ LiveInterval::setFrom(CodePosition from)
{
while (!ranges_.empty()) {
if (ranges_.back().to < from) {
ranges_.erase(&ranges_.back());
ranges_.popBack();
} else {
if (from == ranges_.back().to)
ranges_.erase(&ranges_.back());
ranges_.popBack();
else
ranges_.back().from = from;
break;

View File

@ -543,6 +543,12 @@ class VectorBase : private AllocPolicy
*/
void erase(T* t);
/**
* Removes the elements [|b|, |e|), which must fall in the bounds [begin, end),
* shifting existing elements from |e + 1| onward to b's old position.
*/
void erase(T* b, T *e);
/**
* Measure the size of the vector's heap-allocated storage.
*/
@ -974,10 +980,22 @@ VectorBase<T, N, AP, TV>::erase(T* it)
MOZ_ASSERT(begin() <= it);
MOZ_ASSERT(it < end());
while (it + 1 < end()) {
*it = *(it + 1);
*it = Move(*(it + 1));
++it;
}
popBack();
popBack();
}
template<typename T, size_t N, class AP, class TV>
inline void
VectorBase<T, N, AP, TV>::erase(T* b, T *e)
{
MOZ_ASSERT(begin() <= b);
MOZ_ASSERT(b <= e);
MOZ_ASSERT(e <= end());
while (e < end())
*b++ = Move(*e++);
shrinkBy(e - b);
}
template<typename T, size_t N, class AP, class TV>