foundation - NSString compare efficiency -


string compares can costly. there's statistic floating around says high percent of string compares can eliminated first comparing string sizes. i'm curious know whether nsstring compare: method takes consideration. know?

according sources here (which 1 implementation, others may act differently), compare doesn't check length first, makes sense since it's not equality check. returns less-than/equal-to/greater-than return code, has check characters, if lengths same.

a pure isequal-type method may able shortcut character checks if lengths different, compare not have luxury.

it checks of length against zero, not comparisons of 2 lengths against each other.


Comments

Popular posts from this blog

c++ - Function signature as a function template parameter -

algorithm - What are some ways to combine a number of (potentially incompatible) sorted sub-sets of a total set into a (partial) ordering of the total set? -

How to call a javascript function after the page loads with a chrome extension? -