Speed of NSArray#count
If I do
[myArray count]
is it O(1) or O(n), where n is the number of elements in the array?
The source code of Core Foundation collections (upon which Foundation collections are built) is open source. If you inspect CFArray.c, you’ll see that __CFArrayGetCount()
is O(1).
If it is not O(1) then you should find another array implementation :)
精彩评论