Skip unneeded reallocs in SkTDArray::shrinkToFit()

Change-Id: I885eb1769ffa639026929dc7aa68312e0dbf91b8
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/250037
Reviewed-by: Mike Klein <mtklein@google.com>
Commit-Queue: Florin Malita <fmalita@chromium.org>
This commit is contained in:
Florin Malita 2019-10-22 15:33:59 -04:00 committed by Skia Commit-Bot
parent cc13acbffe
commit 3d5ccfd9d7

View File

@ -319,8 +319,11 @@ public:
#endif
void shrinkToFit() {
fReserve = fCount;
fArray = (T*)sk_realloc_throw(fArray, fReserve * sizeof(T));
if (fReserve != fCount) {
SkASSERT(fReserve > fCount);
fReserve = fCount;
fArray = (T*)sk_realloc_throw(fArray, fReserve * sizeof(T));
}
}
private: