mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-28 15:23:51 +00:00
Bug 1271022 - add Vector::podResizeToFit (r=njn)
MozReview-Commit-ID: 9HTY6O9GY4U --HG-- extra : rebase_source : 55c226d23bd6dbb7b3bb21b356e64ae7499d3f0a
This commit is contained in:
parent
b11e2e12ee
commit
df166c688f
@ -229,6 +229,20 @@ struct VectorImpl<T, N, AP, true>
|
||||
aV.mCapacity = aNewCap;
|
||||
return true;
|
||||
}
|
||||
|
||||
static inline void
|
||||
podResizeToFit(Vector<T, N, AP>& aV)
|
||||
{
|
||||
if (aV.usingInlineStorage() || aV.mLength == aV.mCapacity) {
|
||||
return;
|
||||
}
|
||||
T* newbuf = aV.template pod_realloc<T>(aV.mBegin, aV.mCapacity, aV.mLength);
|
||||
if (MOZ_UNLIKELY(!newbuf)) {
|
||||
return;
|
||||
}
|
||||
aV.mBegin = newbuf;
|
||||
aV.mCapacity = aV.mLength;
|
||||
}
|
||||
};
|
||||
|
||||
// A struct for TestVector.cpp to access private internal fields.
|
||||
@ -559,6 +573,13 @@ public:
|
||||
/** Clears and releases any heap-allocated storage. */
|
||||
void clearAndFree();
|
||||
|
||||
/**
|
||||
* Calls the AllocPolicy's pod_realloc to release excess capacity. Since
|
||||
* realloc is only safe on PODs, this method fails to compile if IsPod<T>
|
||||
* is false.
|
||||
*/
|
||||
void podResizeToFit();
|
||||
|
||||
/**
|
||||
* If true, appending |aNeeded| elements won't reallocate elements storage.
|
||||
* This *doesn't* mean that infallibleAppend may be used! You still must
|
||||
@ -1103,6 +1124,15 @@ Vector<T, N, AP>::clearAndFree()
|
||||
#endif
|
||||
}
|
||||
|
||||
template<typename T, size_t N, class AP>
|
||||
inline void
|
||||
Vector<T, N, AP>::podResizeToFit()
|
||||
{
|
||||
// This function is only defined if IsPod is true and will fail to compile
|
||||
// otherwise.
|
||||
Impl::podResizeToFit(*this);
|
||||
}
|
||||
|
||||
template<typename T, size_t N, class AP>
|
||||
inline bool
|
||||
Vector<T, N, AP>::canAppendWithoutRealloc(size_t aNeeded) const
|
||||
|
Loading…
Reference in New Issue
Block a user