Chromium Code Reviews| Index: include/core/SkTemplates.h |
| diff --git a/include/core/SkTemplates.h b/include/core/SkTemplates.h |
| index b18556b4524b8bb713b25747ff51929a97a8998e..a6cfa52026d58f9cea2b163c4a0de7f1cec3cb7d 100644 |
| --- a/include/core/SkTemplates.h |
| +++ b/include/core/SkTemplates.h |
| @@ -464,6 +464,23 @@ 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 memcpys are safe |
| + void realloc(size_t count) { |
| + if (count > N) { |
| + if (fPtr == fTStorage) { |
| + fPtr = (T*)sk_malloc_flags(count * sizeof(T), SK_MALLOC_THROW | SK_MALLOC_TEMP); |
|
mtklein
2015/04/07 19:27:33
Let's use sk_malloc_throw. I don't believe SK_MAL
|
| + memcpy(fPtr, fTStorage, N); |
| + } else { |
| + fPtr = (T*)sk_realloc_throw(fPtr, count * sizeof(T)); |
| + } |
| + } else if (fPtr != fTStorage) { |
| + memcpy(fTStorage, fPtr, N); |
|
mtklein
2015/04/07 19:27:34
Do you ever really hit this case that you shrink b
|
| + SkDELETE(fPtr); |
| + fPtr = fTStorage; |
| + } |
| + } |
| + |
| private: |
| T* fPtr; |
| union { |