lottie: minor optimization

trim out a group when it has only one child.
This commit is contained in:
Hermet Park 2025-03-26 00:21:36 +09:00 committed by Hermet Park
parent bd520c1c69
commit 51bc7e81f8
2 changed files with 11 additions and 7 deletions

View file

@ -1042,13 +1042,14 @@ void LottieBuilder::updateText(LottieLayer* layer, float frameNo)
auto& textGroupMatrix = textGroup->transform();
auto shape = text->pooling();
shape->reset();
ARRAY_FOREACH(p, glyph->children) {
auto group = static_cast<LottieGroup*>(*p);
ARRAY_FOREACH(p, group->children) {
if (static_cast<LottiePath*>(*p)->pathset(frameNo, SHAPE(shape)->rs.path, nullptr, tween, exps)) {
PAINT(shape)->update(RenderUpdateFlag::Path);
//Either group of a single path
if ((*p)->type == LottieObject::Group) {
ARRAY_FOREACH(p2, static_cast<LottieGroup*>(*p)->children) {
static_cast<LottiePath*>(*p2)->pathset(frameNo, SHAPE(shape)->rs.path, nullptr, tween, exps);
}
}
} else static_cast<LottiePath*>(*p)->pathset(frameNo, SHAPE(shape)->rs.path, nullptr, tween, exps);
}
shape->fill(doc.color.rgb[0], doc.color.rgb[1], doc.color.rgb[2]);
shape->translate(cursor.x - textGroupMatrix.e13, cursor.y - textGroupMatrix.e23);

View file

@ -1079,9 +1079,12 @@ LottieObject* LottieParser::parseGroup()
while (nextArrayValue()) parseObject(group->children);
} else skip();
}
if (group->children.empty()) {
if (group->children.count == 1) {
auto child = group->children.first();
group->children.clear();
delete(group);
return nullptr;
return child;
}
group->prepare();