mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-31 16:50:58 +00:00
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:
parent
69689235ad
commit
01d0fe9852
3 changed files with 41 additions and 7 deletions
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
* Source/Additions/Unicode.m: Optimise somewhat for converting
|
* Source/Additions/Unicode.m: Optimise somewhat for converting
|
||||||
from unicode (UTF-2) to UTF-8
|
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>
|
2009-06-06 Richard Frith-Macdonald <rfm@gnu.org>
|
||||||
|
|
||||||
|
|
|
@ -2094,13 +2094,13 @@ isEqual_c(GSStr self, id anObject)
|
||||||
if (c == NSConstantStringClass)
|
if (c == NSConstantStringClass)
|
||||||
{
|
{
|
||||||
GSStr other = (GSStr)anObject;
|
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 YES;
|
||||||
return NO;
|
return NO;
|
||||||
}
|
}
|
||||||
else if (GSObjCIsKindOf(c, GSStringClass) == YES || c == GSMutableStringClass)
|
else if (c == GSMutableStringClass)
|
||||||
{
|
{
|
||||||
GSStr other = (GSStr)anObject;
|
GSStr other = (GSStr)anObject;
|
||||||
NSRange r = {0, self->_count};
|
NSRange r = {0, self->_count};
|
||||||
|
@ -2125,11 +2125,32 @@ isEqual_c(GSStr self, id anObject)
|
||||||
}
|
}
|
||||||
else
|
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 YES;
|
||||||
}
|
}
|
||||||
return NO;
|
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))
|
else if (GSObjCIsKindOf(c, NSStringClass))
|
||||||
{
|
{
|
||||||
return (*equalImp)((id)self, equalSel, anObject);
|
return (*equalImp)((id)self, equalSel, anObject);
|
||||||
|
|
|
@ -379,13 +379,12 @@ GSEQ_STRCOMP(NSString *ss, NSString *os, unsigned mask, NSRange aRange)
|
||||||
GSEQ_ST s = (GSEQ_ST)ss;
|
GSEQ_ST s = (GSEQ_ST)ss;
|
||||||
GSEQ_OT o = (GSEQ_OT)os;
|
GSEQ_OT o = (GSEQ_OT)os;
|
||||||
unsigned oLength; /* Length of other. */
|
unsigned oLength; /* Length of other. */
|
||||||
unsigned sLength = GSEQ_SLEN;
|
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
/* Range should be checked in calling code */
|
/* Range should be checked in calling code */
|
||||||
if (aRange.location > sLength)
|
if (aRange.location > GSEQ_SLEN)
|
||||||
[NSException raise: NSRangeException format: @"Invalid location."];
|
[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."];
|
[NSException raise: NSRangeException format: @"Invalid location+length."];
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -462,8 +461,13 @@ GSEQ_STRCOMP(NSString *ss, NSString *os, unsigned mask, NSRange aRange)
|
||||||
{
|
{
|
||||||
for (i = 0; i < end; i++)
|
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 c1 = uni_tolower((unichar)sBuf[i]);
|
||||||
unichar c2 = uni_tolower((unichar)oBuf[i]);
|
unichar c2 = uni_tolower((unichar)oBuf[i]);
|
||||||
|
#endif
|
||||||
|
|
||||||
if (c1 < c2)
|
if (c1 < c2)
|
||||||
return NSOrderedAscending;
|
return NSOrderedAscending;
|
||||||
|
@ -475,10 +479,17 @@ GSEQ_STRCOMP(NSString *ss, NSString *os, unsigned mask, NSRange aRange)
|
||||||
{
|
{
|
||||||
for (i = 0; i < end; i++)
|
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])
|
if ((unichar)sBuf[i] < (unichar)oBuf[i])
|
||||||
return NSOrderedAscending;
|
return NSOrderedAscending;
|
||||||
if ((unichar)sBuf[i] > (unichar)oBuf[i])
|
if ((unichar)sBuf[i] > (unichar)oBuf[i])
|
||||||
return NSOrderedDescending;
|
return NSOrderedDescending;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (sLen > oLen)
|
if (sLen > oLen)
|
||||||
|
@ -492,6 +503,7 @@ GSEQ_STRCOMP(NSString *ss, NSString *os, unsigned mask, NSRange aRange)
|
||||||
{
|
{
|
||||||
unsigned start = aRange.location;
|
unsigned start = aRange.location;
|
||||||
unsigned end = start + aRange.length;
|
unsigned end = start + aRange.length;
|
||||||
|
unsigned sLength = GSEQ_SLEN;
|
||||||
unsigned sCount = start;
|
unsigned sCount = start;
|
||||||
unsigned oCount = 0;
|
unsigned oCount = 0;
|
||||||
NSComparisonResult result;
|
NSComparisonResult result;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue