From abb7872b7994f566adf767aa904d4ad70e3a1a39 Mon Sep 17 00:00:00 2001 From: subhransu mohanty Date: Mon, 30 Jul 2018 14:54:42 +0900 Subject: [PATCH] lottie/vector: reserve memory ahead to minimize reallocation. Change-Id: Idb973bb7660c4ec95f36aa36d3707aa6030f5ffc --- src/vector/vpath.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/vector/vpath.cpp b/src/vector/vpath.cpp index dbd1212..e741165 100644 --- a/src/vector/vpath.cpp +++ b/src/vector/vpath.cpp @@ -138,6 +138,7 @@ void VPath::VPathData::arcTo(const VRectF &rect, float startAngle, VPointF curve_start = curvesForArc(rect, startAngle, sweepLength, pts, &point_count); + reserve(point_count + 1, point_count / 3 + 1); if (isEmpty() || forceMoveTo) { moveTo(curve_start); } else { @@ -169,6 +170,7 @@ void VPath::VPathData::addOval(const VRectF &rect, VPath::Direction dir) float h2 = rect.height() / 2; float h2k = h2 * PATH_KAPPA; + reserve(14, 7); // 1Move + 4Cubic + 1Close if (dir == VPath::Direction::CW) { // moveto 12 o'clock. moveTo(VPointF(x + w2, y)); @@ -200,6 +202,7 @@ void VPath::VPathData::addOval(const VRectF &rect, VPath::Direction dir) cubicTo(VPointF(x + w, y + h2 - h2k), VPointF(x + w2 + w2k, y), VPointF(x + w2, y)); } + close(); } void VPath::VPathData::addRect(const VRectF &rect, VPath::Direction dir) @@ -211,6 +214,7 @@ void VPath::VPathData::addRect(const VRectF &rect, VPath::Direction dir) float w = rect.width(); float h = rect.height(); + reserve(6, 6); // 1Move + 4Line + 1Close if (dir == VPath::Direction::CW) { moveTo(VPointF(x + w, y)); lineTo(VPointF(x + w, y + h)); @@ -244,6 +248,7 @@ void VPath::VPathData::addRoundRect(const VRectF &rect, float rx, float ry, if (rx > w) rx = w; if (ry > h) ry = h; + reserve(14, 7); // 1Move + 4Cubic + 1Close if (dir == VPath::Direction::CW) { moveTo(VPointF(x + w, y + ry / 2.f)); arcTo(VRectF(x + w - rx, y + h - ry, rx, ry), 0, -90, false); -- 2.7.4