diff options
author | Mike Reed <reed@google.com> | 2017-03-09 16:36:26 -0500 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-03-09 22:26:12 +0000 |
commit | 6c14c8db4b1378dd1df66401f0a7cc9fc83fe732 (patch) | |
tree | ff2af260ee5f898fb04d3c36793ae086c5ef5213 /include | |
parent | f1b61afbe97199896bfbcadb68758bfcf0dc803a (diff) |
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>
Diffstat (limited to 'include')
-rw-r--r-- | include/private/SkTArray.h | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/include/private/SkTArray.h b/include/private/SkTArray.h index 24fa30b029..22f6d44cea 100644 --- a/include/private/SkTArray.h +++ b/include/private/SkTArray.h @@ -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) { |