lottie/render: fixed logic where the memory will only grow when needed. 48/185748/1
authorsubhransu mohanty <sub.mohanty@samsung.com>
Thu, 2 Aug 2018 04:11:28 +0000 (13:11 +0900)
committersubhransu mohanty <sub.mohanty@samsung.com>
Thu, 2 Aug 2018 04:11:28 +0000 (13:11 +0900)
Change-Id: I2367433c69083b5c52d109ff854b9fa3b9019247

src/vector/vraster.cpp

index 0e07e0f..6921984 100644 (file)
@@ -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<SW_FT_Vector *>(mMemory);
-    ft.tags = reinterpret_cast<char *>(mMemory + point_size);
-    ft.contours = reinterpret_cast<short *>(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)