From 6b6c8625a0f5db8b7d7960abcd2f053d8a6de886 Mon Sep 17 00:00:00 2001 From: cosmonaut Date: Thu, 21 Jul 2022 17:37:13 -0700 Subject: [PATCH] backwards iterators --- src/cram.c | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/src/cram.c b/src/cram.c index 2944eca..9f3de63 100644 --- a/src/cram.c +++ b/src/cram.c @@ -298,7 +298,7 @@ void Cram_Internal_PruneRects(RectPackContext* context) for (i = 0; i < context->freeRectangleCount; i += 1) { - for (j = 0; j < context->newFreeRectangleCount;) + for (j = context->newFreeRectangleCount - 1; j >= 0; j -= 1) { if (Cram_Internal_Contains(&context->freeRectangles[i], &context->newFreeRectangles[j])) { @@ -306,10 +306,6 @@ void Cram_Internal_PruneRects(RectPackContext* context) context->newFreeRectangles[j] = context->newFreeRectangles[context->newFreeRectangleCount - 1]; context->newFreeRectangleCount -= 1; } - else - { - j += 1; - } } } @@ -418,7 +414,7 @@ void Cram_Internal_PlaceRect(RectPackContext *context, Rect *rect) Rect *freeRect; int32_t i; - for (i = 0; i < context->freeRectangleCount;) + for (i = context->freeRectangleCount - 1; i >= 0; i -= 1) { freeRect = &context->freeRectangles[i]; @@ -428,10 +424,6 @@ void Cram_Internal_PlaceRect(RectPackContext *context, Rect *rect) context->freeRectangles[i] = context->freeRectangles[context->freeRectangleCount - 1]; context->freeRectangleCount -= 1; } - else - { - i += 1; - } } Cram_Internal_PruneRects(context);