Update AMTL with a number of changes.
- Introduce HashMap, a key-value map based on HashTable. - Introduce LinkedList, to port from SourceHook::List. - Introduce AString, to port from SourceHook::String. - Introduce KE_OVERRIDE and KE_DELETE helpers for C++11. - HashTable now constructs/destructs only live items. - Fix insert-on-removed-item bug in HashTable. - Fix Vector keeping a new maxsize if allocation fails. - Renamed am-inline-list.h to am-inlinelist.h. --HG-- rename : public/amtl/am-inline-list.h => public/amtl/am-inlinelist.h
This commit is contained in:
+17
-9
@@ -48,8 +48,7 @@ class Vector : public AllocPolicy
|
||||
{
|
||||
}
|
||||
|
||||
~Vector()
|
||||
{
|
||||
~Vector() {
|
||||
zap();
|
||||
}
|
||||
|
||||
@@ -61,7 +60,7 @@ class Vector : public AllocPolicy
|
||||
other.reset();
|
||||
}
|
||||
|
||||
bool append(const T& item) {
|
||||
bool append(const T &item) {
|
||||
if (!growIfNeeded(1))
|
||||
return false;
|
||||
new (&data_[nitems_]) T(item);
|
||||
@@ -124,6 +123,12 @@ class Vector : public AllocPolicy
|
||||
return growIfNeeded(desired - length());
|
||||
}
|
||||
|
||||
private:
|
||||
// These are disallowed because they basically violate the failure handling
|
||||
// model for AllocPolicies and are also likely to have abysmal performance.
|
||||
Vector(const Vector<T> &other) KE_DELETE;
|
||||
Vector &operator =(const Vector<T> &other) KE_DELETE;
|
||||
|
||||
private:
|
||||
void zap() {
|
||||
for (size_t i = 0; i < nitems_; i++)
|
||||
@@ -144,16 +149,17 @@ class Vector : public AllocPolicy
|
||||
}
|
||||
if (nitems_ + needed < maxsize_)
|
||||
return true;
|
||||
if (maxsize_ == 0)
|
||||
maxsize_ = 8;
|
||||
while (nitems_ + needed > maxsize_) {
|
||||
if (!IsUintPtrMultiplySafe(maxsize_, 2)) {
|
||||
|
||||
size_t new_maxsize = maxsize_ ? maxsize_ : 8;
|
||||
while (nitems_ + needed > new_maxsize) {
|
||||
if (!IsUintPtrMultiplySafe(new_maxsize, 2)) {
|
||||
this->reportAllocationOverflow();
|
||||
return false;
|
||||
}
|
||||
maxsize_ *= 2;
|
||||
new_maxsize *= 2;
|
||||
}
|
||||
T* newdata = (T*)this->malloc(sizeof(T) * maxsize_);
|
||||
|
||||
T* newdata = (T*)this->malloc(sizeof(T) * new_maxsize);
|
||||
if (newdata == NULL)
|
||||
return false;
|
||||
for (size_t i = 0; i < nitems_; i++) {
|
||||
@@ -161,7 +167,9 @@ class Vector : public AllocPolicy
|
||||
data_[i].~T();
|
||||
}
|
||||
this->free(data_);
|
||||
|
||||
data_ = newdata;
|
||||
maxsize_ = new_maxsize;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user