Index: include/core/SkTemplates.h |
diff --git a/include/core/SkTemplates.h b/include/core/SkTemplates.h |
index b18556b4524b8bb713b25747ff51929a97a8998e..54d4d5dbfbc0314f6c417ebc4615ff43c52e5ade 100644 |
--- a/include/core/SkTemplates.h |
+++ b/include/core/SkTemplates.h |
@@ -464,6 +464,17 @@ public: |
return fPtr[index]; |
} |
+ // Reallocs the array, can be used to shrink the allocation. By reset above, we know fPtr's |
+ // size is > N so the below memcpy is safe |
+ void realloc(size_t count) { |
mtklein
2015/04/07 19:59:44
Don't we still need a count > N check for safety?
|
+ if (fPtr == fTStorage) { |
+ fPtr = (T*)sk_malloc_throw(count * sizeof(T)); |
+ memcpy(fPtr, fTStorage, N); |
+ } else { |
+ fPtr = (T*)sk_realloc_throw(fPtr, count * sizeof(T)); |
+ } |
+ } |
+ |
private: |
T* fPtr; |
union { |