Effective loop through AS3 dictionary

for (var k in dictionary) { var key:KeyType = KeyType(k); var value:ValType = ValType(dictionary[k]); // <-- lookup // do stuff } 

This is what I use to scroll through entries in a dictionary. As you can see in each iteration, I do a search in a dictionary. Is there a more efficient way to iterate the dictionary (while maintaining access to the key)?

+45
iterator iteration actionscript-3
Mar 05 '10 at 12:53 on
source share
2 answers

Iterating through keys and values :

 for (var k:Object in dictionary) { var value:ValType = dictionary[k]; var key:KeyType = k; } 

More compressed values :

 for each (var value:ValType in dictionary) { } 
+64
Mar 05 '10 at 13:16
source share

There are 3 different for loops in AS3, you should use the one that best suits your needs.

Programmers spend a huge amount of time thinking or worrying about the speed of non-critical parts of their programs and these attempts at efficiency actually have a strong negative impact on debugging and maintenance. We must forget about low efficiency, say, about 97% of the time: premature optimization is the root of all evil. But we must not miss our opportunity in these critical 3%.

Donald whip

-one
Sep 16 '16 at 15:33
source share



All Articles