mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-30 16:30:41 +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
f074015e89
commit
ed902f9bcf
3 changed files with 41 additions and 7 deletions
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue