commmon: ++neat code

introduced ARRAY_REVERSE_FOREACH() macro.
This commit is contained in:
Hermet Park 2025-02-03 21:41:57 +09:00 committed by Hermet Park
parent 580019b64b
commit 8833cc8521
3 changed files with 8 additions and 5 deletions

View file

@ -30,6 +30,9 @@
#define ARRAY_FOREACH(A, B) \
for (auto A = (B).begin(); A < (B).end(); ++A)
#define ARRAY_REVERSE_FOREACH(A, B) \
for (auto A = (B).end() - 1; A >= (B).begin(); --A)
namespace tvg
{

View file

@ -325,7 +325,7 @@ static void _repeat(LottieGroup* parent, Shape* path, RenderContext* ctx)
propagators.push(ctx->propagator);
Array<Shape*> shapes;
for (auto repeater = ctx->repeaters.end() - 1; repeater >= ctx->repeaters.begin(); --repeater) {
ARRAY_REVERSE_FOREACH(repeater, ctx->repeaters) {
shapes.reserve(repeater->cnt);
for (int i = 0; i < repeater->cnt; ++i) {
@ -363,7 +363,7 @@ static void _repeat(LottieGroup* parent, Shape* path, RenderContext* ctx)
propagators.push(*p);
}
} else if (!shapes.empty()) {
for (auto shape = shapes.end() - 1; shape >= shapes.begin(); --shape) {
ARRAY_REVERSE_FOREACH(shape, shapes) {
parent->scene->push(*shape);
propagators.push(*shape);
}
@ -949,7 +949,7 @@ void LottieBuilder::updatePrecomp(LottieComposition* comp, LottieLayer* precomp,
frameNo = precomp->remap(comp, frameNo, exps);
for (auto c = precomp->children.end() - 1; c >= precomp->children.begin(); --c) {
ARRAY_REVERSE_FOREACH(c, precomp->children) {
auto child = static_cast<LottieLayer*>(*c);
if (!child->matteSrc) updateLayer(comp, precomp->scene, child, frameNo);
}
@ -1589,7 +1589,7 @@ bool LottieBuilder::update(LottieComposition* comp, float frameNo)
if (exps && comp->expressions) exps->update(comp->timeAtFrame(frameNo));
for (auto child = root->children.end() - 1; child >= root->children.begin(); --child) {
ARRAY_REVERSE_FOREACH(child, root->children) {
auto layer = static_cast<LottieLayer*>(*child);
if (!layer->matteSrc) updateLayer(comp, root->scene, layer, frameNo);
}

View file

@ -409,7 +409,7 @@ void LottieGroup::prepare(LottieObject::Type type)
size_t strokeCnt = 0;
size_t fillCnt = 0;
for (auto c = children.end() - 1; c >= children.begin(); --c) {
ARRAY_REVERSE_FOREACH(c, children) {
auto child = static_cast<LottieObject*>(*c);
if (child->type == LottieObject::Type::Trimpath) trimpath = true;