Sync am-vector.h with AMTL (fix bug 6090).
--HG-- extra : rebase_source : f27515a516db9bc14779da3721f6378d573584b5
This commit is contained in:
parent
7248ad9aba
commit
b6792a2c8c
@ -167,6 +167,14 @@ class Vector : public AllocPolicy
|
|||||||
return growIfNeeded(desired - length());
|
return growIfNeeded(desired - length());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Vector &operator =(Moveable<Vector<T, AllocPolicy> > other) {
|
||||||
|
data_ = other->data_;
|
||||||
|
nitems_ = other->nitems_;
|
||||||
|
maxsize_ = other->maxsize_;
|
||||||
|
other->reset();
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// These are disallowed because they basically violate the failure handling
|
// These are disallowed because they basically violate the failure handling
|
||||||
// model for AllocPolicies and are also likely to have abysmal performance.
|
// model for AllocPolicies and are also likely to have abysmal performance.
|
||||||
@ -186,10 +194,15 @@ class Vector : public AllocPolicy
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool moveUp(size_t at) {
|
bool moveUp(size_t at) {
|
||||||
assert(at < nitems_);
|
// Note: we don't use append() here. Passing an element as a Moveable into
|
||||||
if (!append(Moveable<T>(data_[nitems_ - 1])))
|
// insert() or append() can break, since the underlying storage could be
|
||||||
|
// reallocated, invalidating the Moveable reference. Instead, we inline
|
||||||
|
// the logic to append() to ensure growIfNeeded occurs before any
|
||||||
|
// references are taken.
|
||||||
|
if (!growIfNeeded(1))
|
||||||
return false;
|
return false;
|
||||||
|
new (&data_[nitems_]) T(Moveable<T>(data_[nitems_ - 1]));
|
||||||
|
nitems_++;
|
||||||
for (size_t i = nitems_ - 2; i > at; i--)
|
for (size_t i = nitems_ - 2; i > at; i--)
|
||||||
data_[i] = Moveable<T>(data_[i - 1]);
|
data_[i] = Moveable<T>(data_[i - 1]);
|
||||||
return true;
|
return true;
|
||||||
|
Loading…
Reference in New Issue
Block a user