I have a linked list class that stores a linked collection of entities.
I’ve added an iterate() method to this class which I am sceptical of. It accepts a function as its only argument, which should accept an instance of Entity only.
i.e.
list.iterate(function(entity:Entity)
{
trace(entity.id);
});
I’m concerned about this method because I’m not sure what will happen to the function I’ve given to iterate() in this case. Will what I’m doing hurt the performance or memory usage of my game at all when compared to doing my iterations manually like so?:
var i:Entity = list.first;
while(i != null)
{
trace(i.id);
i = i.next;
}
Any information on this is appreciated.
is worse than
if you have a similar while loop in your iterate function because you add the overhead of calling the nested function.
And the while loop will be I guess more performant than using something like this:
because there is still the overhead of calling a function, even if it is less than the overhead of the nested function.