Efficient looping through AS3 dictionary

前端 未结 2 795
梦谈多话
梦谈多话 2020-12-25 09:55
for (var k in dictionary) 
{
  var key:KeyType = KeyType(k);
  var value:ValType = ValType(dictionary[k]); // <-- lookup
  // do stuff
}

This is

相关标签:
2条回答
  • 2020-12-25 10:47

    In AS3 there are 3 different for loops, you should use one that suits your needs best.

    Programmers waste enormous amounts of time thinking about, or worrying about, the speed of noncritical parts of their programs, and these attempts at efficiency actually have a strong negative impact when debugging and maintenance are considered. We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil. Yet we should not pass up our opportunities in that critical 3%.

    Donald Knuth

    0 讨论(0)
  • 2020-12-25 10:59

    Iterate through keys & values:

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

    Iterate through values more concisely:

    for each (var value:ValType in dictionary) {
    
    }
    
    0 讨论(0)
提交回复
热议问题