From: sub.mohanty@samsung.com Date: Sat, 24 Aug 2019 11:35:56 +0000 (+0900) Subject: rlottie: refactor to avoid reversing the vector X-Git-Tag: submit/tizen/20190905.064609~7 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=89f85884fdf35471ee17ef778977a675739b48a0;p=platform%2Fcore%2Fuifw%2Flottie-player.git rlottie: refactor to avoid reversing the vector Change-Id: I981c1dfbb0465af32032afab191f7dfd82fd513c --- diff --git a/src/lottie/lottieitem.cpp b/src/lottie/lottieitem.cpp index b68755e..7e7cd97 100644 --- a/src/lottie/lottieitem.cpp +++ b/src/lottie/lottieitem.cpp @@ -511,9 +511,14 @@ bool LOTLayerItem::visible() const LOTCompLayerItem::LOTCompLayerItem(LOTLayerData *layerModel) : LOTLayerItem(layerModel) { - // 1. create layer item - for (auto &i : mLayerData->mChildren) { - auto model = static_cast(i.get()); + if (!mLayerData->mChildren.empty()) + mLayers.reserve(mLayerData->mChildren.size()); + + // 1. keep the layer in back-to-front order. + // as lottie model keeps the data in front-toback-order. + for (auto it = mLayerData->mChildren.crbegin(); + it != mLayerData->mChildren.rend(); ++it ) { + auto model = static_cast((*it).get()); auto item = LOTCompItem::createLayerItem(model); if (item) mLayers.push_back(std::move(item)); } @@ -529,10 +534,6 @@ LOTCompLayerItem::LOTCompLayerItem(LOTLayerData *layerModel) } } - // 3. keep the layer in back-to-front order. - // as lottie model keeps the data in front-toback-order. - std::reverse(mLayers.begin(), mLayers.end()); - // 4. check if its a nested composition if (!layerModel->layerSize().empty()) { mClipper = std::make_unique(layerModel->layerSize()); @@ -1024,16 +1025,18 @@ void LOTContentGroupItem::addChildren(LOTGroupData *data) { if (!data) return; - for (auto &i : data->mChildren) { - auto content = LOTShapeLayerItem::createContentItem(i.get()); + if (!data->mChildren.empty()) mContents.reserve(data->mChildren.size()); + + // keep the content in back-to-front order. + // as lottie model keeps it in front-to-back order. + for (auto it = data->mChildren.crbegin(); it != data->mChildren.rend(); + ++it ) { + auto content = LOTShapeLayerItem::createContentItem((*it).get()); if (content) { content->setParent(this); mContents.push_back(std::move(content)); } } - - // keep the content in back-to-front order. - std::reverse(mContents.begin(), mContents.end()); } void LOTContentGroupItem::update(int frameNo, const VMatrix &parentMatrix,