From 3d5ccfd9d7cc8f5b5026b00dcdf8c8f639145200 Mon Sep 17 00:00:00 2001 From: Florin Malita Date: Tue, 22 Oct 2019 15:33:59 -0400 Subject: [PATCH] Skip unneeded reallocs in SkTDArray::shrinkToFit() Change-Id: I885eb1769ffa639026929dc7aa68312e0dbf91b8 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/250037 Reviewed-by: Mike Klein Commit-Queue: Florin Malita --- include/private/SkTDArray.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/include/private/SkTDArray.h b/include/private/SkTDArray.h index 59c180bcde..f4d2e7c3ea 100644 --- a/include/private/SkTDArray.h +++ b/include/private/SkTDArray.h @@ -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: