take fast case in swap() if we're using malloc OR we're empty
This avoids taking the (more expensive) copy case when we don't need to. The old behavior only took this fast case if we were "actively" using a dynamically allocated array. BUG=skia: Change-Id: I0f606ba83ff4aff3a8fc282db7a3ce1b0191fb1a Reviewed-on: https://skia-review.googlesource.com/9521 Reviewed-by: Brian Osman <brianosman@google.com> Commit-Queue: Mike Reed <reed@google.com>
This commit is contained in:
parent
f1b61afbe9
commit
6c14c8db4b
@ -293,9 +293,7 @@ public:
|
||||
if (this == that) {
|
||||
return;
|
||||
}
|
||||
if (this->fPreAllocMemArray != this->fItemArray &&
|
||||
that->fPreAllocMemArray != that->fItemArray) {
|
||||
// If neither is using a preallocated array then just swap.
|
||||
if (this->isNotUsingPreAlloc() && that->isNotUsingPreAlloc()) {
|
||||
SkTSwap(fItemArray, that->fItemArray);
|
||||
SkTSwap(fCount, that->fCount);
|
||||
SkTSwap(fAllocCount, that->fAllocCount);
|
||||
@ -477,6 +475,10 @@ private:
|
||||
|
||||
static const int gMIN_ALLOC_COUNT = 8;
|
||||
|
||||
inline bool isNotUsingPreAlloc() const {
|
||||
return !fItemArray || fPreAllocMemArray != fItemArray;
|
||||
}
|
||||
|
||||
// Helper function that makes space for n objects, adjusts the count, but does not initialize
|
||||
// the new objects.
|
||||
void* push_back_raw(int n) {
|
||||
|
Loading…
Reference in New Issue
Block a user