diff --git a/ChangeLog b/ChangeLog index ee99028ba..4651ee7d6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,6 +2,7 @@ * Source/Additions/Unicode.m: Optimise somewhat for converting from unicode (UTF-2) to UTF-8 + * Source/GSString.m: Optimise 8 bit string equality tests a little. 2009-06-06 Richard Frith-Macdonald diff --git a/Source/GSString.m b/Source/GSString.m index 0f0040d45..74d692626 100644 --- a/Source/GSString.m +++ b/Source/GSString.m @@ -2094,13 +2094,13 @@ isEqual_c(GSStr self, id anObject) if (c == NSConstantStringClass) { GSStr other = (GSStr)anObject; - NSRange r = {0, self->_count}; - if (strCompCsCs((id)self, (id)other, 0, r) == NSOrderedSame) + if (other->_count == self->_count + && memcmp(other->_contents.c, self->_contents.c, self->_count) == 0) return YES; return NO; } - else if (GSObjCIsKindOf(c, GSStringClass) == YES || c == GSMutableStringClass) + else if (c == GSMutableStringClass) { GSStr other = (GSStr)anObject; NSRange r = {0, self->_count}; @@ -2125,11 +2125,32 @@ isEqual_c(GSStr self, id anObject) } else { - if (strCompCsCs((id)self, (id)other, 0, r) == NSOrderedSame) + if (other->_count == self->_count + && memcmp(other->_contents.c, self->_contents.c, self->_count) == 0) return YES; } return NO; } + else if (GSObjCIsKindOf(c, GSStringClass) == YES) + { + GSStr other = (GSStr)anObject; + + /* + * First see if the hash is the same - if not, we can't be equal. + */ + if (self->_flags.hash == 0) + self->_flags.hash = (*hashImp)((id)self, hashSel); + if (other->_flags.hash == 0) + other->_flags.hash = (*hashImp)((id)other, hashSel); + if (self->_flags.hash != other->_flags.hash) + return NO; + + if (other->_count == self->_count + && memcmp(other->_contents.c, self->_contents.c, self->_count) == 0) + return YES; + + return NO; + } else if (GSObjCIsKindOf(c, NSStringClass)) { return (*equalImp)((id)self, equalSel, anObject); diff --git a/Source/GSeq.h b/Source/GSeq.h index 848203e07..f660ff416 100644 --- a/Source/GSeq.h +++ b/Source/GSeq.h @@ -379,13 +379,12 @@ GSEQ_STRCOMP(NSString *ss, NSString *os, unsigned mask, NSRange aRange) GSEQ_ST s = (GSEQ_ST)ss; GSEQ_OT o = (GSEQ_OT)os; unsigned oLength; /* Length of other. */ - unsigned sLength = GSEQ_SLEN; #if 0 /* Range should be checked in calling code */ - if (aRange.location > sLength) + if (aRange.location > GSEQ_SLEN) [NSException raise: NSRangeException format: @"Invalid location."]; - if (aRange.length > (sLength - aRange.location)) + if (aRange.length > (GSEQ_SLEN - aRange.location)) [NSException raise: NSRangeException format: @"Invalid location+length."]; #endif @@ -462,8 +461,13 @@ GSEQ_STRCOMP(NSString *ss, NSString *os, unsigned mask, NSRange aRange) { for (i = 0; i < end; i++) { +#if GSEQ_O == GSEQ_CS && GSEQ_S == GSEQ_CS + char c1 = tolower(sBuf[i]); + char c2 = tolower(oBuf[i]); +#else unichar c1 = uni_tolower((unichar)sBuf[i]); unichar c2 = uni_tolower((unichar)oBuf[i]); +#endif if (c1 < c2) return NSOrderedAscending; @@ -475,10 +479,17 @@ GSEQ_STRCOMP(NSString *ss, NSString *os, unsigned mask, NSRange aRange) { for (i = 0; i < end; i++) { +#if GSEQ_O == GSEQ_CS && GSEQ_S == GSEQ_CS + if (sBuf[i] < oBuf[i]) + return NSOrderedAscending; + if (sBuf[i] > oBuf[i]) + return NSOrderedDescending; +#else if ((unichar)sBuf[i] < (unichar)oBuf[i]) return NSOrderedAscending; if ((unichar)sBuf[i] > (unichar)oBuf[i]) return NSOrderedDescending; +#endif } } if (sLen > oLen) @@ -492,6 +503,7 @@ GSEQ_STRCOMP(NSString *ss, NSString *os, unsigned mask, NSRange aRange) { unsigned start = aRange.location; unsigned end = start + aRange.length; + unsigned sLength = GSEQ_SLEN; unsigned sCount = start; unsigned oCount = 0; NSComparisonResult result;