Does anybody know whether NSFastEnumeration is really faster (as in run-time performance) than using NSEnumerator or (for arrays) using an integer counter and loop through the elements?
If it is indeed faster, how does it achieve that speed?
Or perhaps the “fast” actually refers to faster in writing the iteration code?
Thanks in advance.
Depending on the container,
NSFastEnumerationis at least as fast asNSEnumeratorbut usually much faster since it involves fewer method calls.Instead of having to call
nextObjectfor every item in the array, withNSFastEnumeratorthe array can give back a block of objects in a C array at once. Iterating that C array is way faster than having to do lots of method calls, which each look up and return just one object.