From e8cd1a9ba7ea8e74df1d2474bfe8e1c08114cbc3 Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Mon, 16 Aug 2010 21:40:14 +0000 Subject: [PATCH] Minor optimisation in the garbage collection order. --- src/ticker.cpp | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/src/ticker.cpp b/src/ticker.cpp index 7e354714..c2f8cebd 100644 --- a/src/ticker.cpp +++ b/src/ticker.cpp @@ -79,19 +79,9 @@ void Ticker::TickGame() data->delta_time = data->timer.GetSeconds(); data->bias += data->delta_time; - /* Insert waiting objects in the appropriate lists */ - while (data->todo) - { - Asset *a = data->todo; - data->todo = a->next; - - int i = a->GetGroup(); - a->next = data->list[i]; - data->list[i] = a; - data->nassets++; - } - - /* Garbage collect objects that can be destroyed */ + /* Garbage collect objects that can be destroyed. We can do this + * before inserting awaiting objects, because there is no way these + * are already marked for destruction. */ for (int i = 0; i < Asset::GROUP_COUNT; i++) for (Asset *a = data->list[i], *prev = NULL; a; prev = a, a = a->next) if (a->destroy) @@ -105,6 +95,18 @@ void Ticker::TickGame() delete a; } + /* Insert waiting objects into the appropriate lists */ + while (data->todo) + { + Asset *a = data->todo; + data->todo = a->next; + + int i = a->GetGroup(); + a->next = data->list[i]; + data->list[i] = a; + data->nassets++; + } + /* Tick objects for the game loop */ for (int i = 0; i < Asset::GROUP_COUNT; i++) for (Asset *a = data->list[i]; a; a = a->next)