Minor optimisation.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@28335 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-MacDonald 2009-06-08 16:03:54 +00:00
parent 69689235ad
commit 01d0fe9852
3 changed files with 41 additions and 7 deletions

View file

@ -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 <rfm@gnu.org>

View file

@ -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);

View file

@ -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;