Typically, a string object retains its length, and therefore getting and comparing an integer is very fast and has less memory access than equals (), where you - in the worst case - need to check the length and loop over characters.
In any case, the string equals () method must also check the length first, and therefore it should be - almost - at the same speed as the length check.
equal to the part in Java (http://www.docjar.com/html/api/java/lang/String.java.html):
int n = count; if (n == anotherString.count) {...}
equal to the part in Objective-C (http://www.opensource.apple.com/source/CF/CF-476.15/CFString.c) - NSString is based on CFString:
if (len1 != __CFStrLength2(str2, contents2)) return false;
Daniel MΓΌhlbachler
source share