Remove MenuManager use of memtables (bug 5899 part 2, r=fyren).

This commit is contained in:
David Anderson
2013-08-31 11:50:28 -07:00
parent a25f9010cc
commit 435f2b8e39
6 changed files with 82 additions and 58 deletions
+32
View File
@@ -85,6 +85,29 @@ class Vector : public AllocPolicy
nitems_++;
}
// Shift all elements including |at| up by one, and insert |item| at the
// given position. This is a linear-time operation.
bool insert(size_t at, const T &item) {
if (!moveUp(at))
return false;
new (&data_[at]) T(item);
return true;
}
bool insert(size_t at, Moveable<T> item) {
if (!moveUp(at))
return false;
new (&data_[at]) T(item);
return true;
}
// Shift all elements at the given position down, removing the given
// element. This is a linear-time operation.
void remove(size_t at) {
for (size_t i = at; i < length() - 1; i++)
data_[i] = T(Moveable<T>(data_[i + 1]));
pop();
}
T popCopy() {
T t = at(length() - 1);
pop();
@@ -154,6 +177,15 @@ class Vector : public AllocPolicy
maxsize_ = 0;
}
bool moveUp(size_t at) {
if (!growIfNeeded(1))
return false;
nitems_++;
for (size_t i = nitems_ - 1; i > at; i--)
data_[i] = T(Moveable<T>(data_[i - 1]));
return true;
}
bool growIfNeeded(size_t needed)
{
if (!IsUintPtrAddSafe(nitems_, needed)) {