From 6d5d456d0fdd51d0b537ce6c50a7172376fedac7 Mon Sep 17 00:00:00 2001 From: subhransu mohanty Date: Thu, 26 Jul 2018 11:23:14 +0900 Subject: [PATCH] lottie/optimization: reserve() memory ahead before calling path api to optimize the number of allocation. Change-Id: Iab0b8db715c868de0a0f4a0c688421cc11be4b01 --- src/lottie/lottieitem.cpp | 18 +----------------- src/lottie/lottiemodel.h | 5 +++++ 2 files changed, 6 insertions(+), 17 deletions(-) diff --git a/src/lottie/lottieitem.cpp b/src/lottie/lottieitem.cpp index a55bc3c..51bfe91 100644 --- a/src/lottie/lottieitem.cpp +++ b/src/lottie/lottieitem.cpp @@ -904,23 +904,7 @@ LOTShapeItem::LOTShapeItem(LOTShapeData *data):LOTPathDataItem(data->isStatic()) VPath LOTShapeItem::getPath(int frameNo) { - LottieShapeData shapeData = mData->mShape.value(frameNo); - - if (shapeData.mPoints.empty()) - return VPath(); - - VPath path; - - int size = shapeData.mPoints.size(); - const VPointF *points = shapeData.mPoints.data(); - path.moveTo(points[0]); - for (int i = 1 ; i < size; i+=3) { - path.cubicTo(points[i], points[i+1], points[i+2]); - } - if (shapeData.mClosed) - path.close(); - - return path; + return mData->mShape.value(frameNo).toPath(); } diff --git a/src/lottie/lottiemodel.h b/src/lottie/lottiemodel.h index fc3475e..9e37dc1 100644 --- a/src/lottie/lottiemodel.h +++ b/src/lottie/lottiemodel.h @@ -109,6 +109,11 @@ public: VPath path; int size = mPoints.size(); const VPointF *points = mPoints.data(); + /* reserve exact memory requirement at once + * ptSize = size + 1(size + close) + * elmSize = size/3 cubic + 1 move + 1 close + */ + path.reserve(size + 1 , size/3 + 2); path.moveTo(points[0]); for (int i = 1 ; i < size; i+=3) { path.cubicTo(points[i], points[i+1], points[i+2]); -- 2.34.1