Fix TODO in SkTArray move constructor.
If moving from an SkTArray which owns its own memory, just steal it
instead of always making a copy.
Change-Id: Ic969437a39d23d878d752bbdee38aa5dd2472e21
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/290125
Reviewed-by: Mike Klein <mtklein@google.com>
Commit-Queue: Ben Wagner <bungeman@google.com>
diff --git a/include/private/SkTArray.h b/include/private/SkTArray.h
index 78ce51b..84d7ddb 100644
--- a/include/private/SkTArray.h
+++ b/include/private/SkTArray.h
@@ -47,10 +47,23 @@
}
SkTArray(SkTArray&& that) {
- // TODO: If 'that' owns its memory why don't we just steal the pointer?
- this->init(that.fCount);
- that.move(fItemArray);
- that.fCount = 0;
+ if (that.fOwnMemory) {
+ fItemArray = that.fItemArray;
+ fCount = that.fCount;
+ fAllocCount = that.fAllocCount;
+ fOwnMemory = true;
+ fReserved = that.fReserved;
+
+ that.fItemArray = nullptr;
+ that.fCount = 0;
+ that.fAllocCount = 0;
+ that.fOwnMemory = true;
+ that.fReserved = false;
+ } else {
+ this->init(that.fCount);
+ that.move(fItemArray);
+ that.fCount = 0;
+ }
}
/**