From 3ef4a6b6aec8f0be11355a6109680ba93808ecc4 Mon Sep 17 00:00:00 2001 From: subhransu mohanty Date: Thu, 2 Aug 2018 13:11:28 +0900 Subject: [PATCH] lottie/render: fixed logic where the memory will only grow when needed. Change-Id: I2367433c69083b5c52d109ff854b9fa3b9019247 --- src/vector/vraster.cpp | 52 +++++++++++++++++++----------------------- 1 file changed, 24 insertions(+), 28 deletions(-) diff --git a/src/vector/vraster.cpp b/src/vector/vraster.cpp index 0e07e0f..6921984 100644 --- a/src/vector/vraster.cpp +++ b/src/vector/vraster.cpp @@ -12,14 +12,11 @@ V_BEGIN_NAMESPACE struct FTOutline { public: - FTOutline() : mMemory(nullptr) {} - ~FTOutline() { delete[] mMemory; } - void releaseMemory() + ~FTOutline() { - if (mMemory) delete[] mMemory; - mMemory = nullptr; - mPointSize = 0; - mSegmentSize = 0; + if (mPointSize) delete[] ft.points; + if (mTagSize) delete[] ft.tags; + if (mSegmentSize) delete[] ft.contours; } void reset(); void grow(int, int); @@ -32,9 +29,9 @@ public: void end(); void transform(const VMatrix &m); SW_FT_Outline ft; - SW_FT_Vector * mMemory{nullptr}; int mPointSize{0}; int mSegmentSize{0}; + int mTagSize{0}; bool closed{false}; SW_FT_Stroker_LineCap ftCap; SW_FT_Stroker_LineJoin ftJoin; @@ -52,29 +49,28 @@ void FTOutline::reset() void FTOutline::grow(int points, int segments) { reset(); - if (mPointSize >= points && mSegmentSize >= segments) return; - // release old memory - releaseMemory(); + int point_size = (points + segments); + int segment_size = (sizeof(short) * segments); + int tag_size = (sizeof(char) * (points + segments)); - // update book keeping - mPointSize = points; - mSegmentSize = segments; + if (point_size > mPointSize) { + if (mPointSize) delete [] ft.points; + ft.points = new SW_FT_Vector[point_size]; + mPointSize = point_size; + } - int point_size = (points + segments); - int contour_size = ((sizeof(short) * segments) / sizeof(SW_FT_Vector)) + 1; - int tag_size = - ((sizeof(char) * (points + segments)) / sizeof(SW_FT_Vector)) + 1; - - /* - * Optimization, instead of allocating 3 different buffer - * allocate one big buffer and divide the buffer into 3 different - * segment. - */ - mMemory = new SW_FT_Vector[point_size + contour_size + tag_size]; - ft.points = reinterpret_cast(mMemory); - ft.tags = reinterpret_cast(mMemory + point_size); - ft.contours = reinterpret_cast(mMemory + point_size + tag_size); + if (segment_size > mSegmentSize) { + if (mSegmentSize) delete [] ft.contours; + ft.contours = new short[segment_size]; + mSegmentSize = segment_size; + } + + if (tag_size > mTagSize) { + if (mTagSize) delete [] ft.tags; + ft.tags = new char[tag_size]; + mTagSize = tag_size; + } } void FTOutline::convert(const VPath &path) -- 2.34.1