minor optimisations

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@31433 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-MacDonald 2010-09-28 13:23:53 +00:00
parent 52d7256b41
commit 42828af0cc
3 changed files with 182 additions and 50 deletions

View file

@ -2824,6 +2824,12 @@ transmute(GSStr self, NSString *aString)
setup(YES);
}
- (id) copyWithZone: (NSZone*)z
{
[self subclassResponsibility: _cmd];
return nil;
}
/*
* Return a 28-bit hash value for the string contents - this
* MUST match the algorithm used by the NSString base class.
@ -2980,10 +2986,84 @@ transmute(GSStr self, NSString *aString)
freeWhenDone: flag];
}
- (id) copyWithZone: (NSZone*)z
- (id) lowercaseString
{
[self subclassResponsibility: _cmd];
return nil;
if (_flags.wide == 1)
{
GSUnicodeInlineString *o;
unsigned i;
o = (typeof(o))NSAllocateObject(GSUnicodeInlineStringClass,
_count * sizeof(unichar), NSDefaultMallocZone());
o->_contents.u = (unichar*)
(((void*)o)+class_getInstanceSize(GSUnicodeInlineStringClass));
i = o->_count = _count;
while (i-- > 0)
{
o->_contents.u[i] = uni_tolower(_contents.u[i]);
}
o->_flags.wide = 1;
o->_flags.owned = 1; // Ignored on dealloc, but means we own buffer
return [(id)o autorelease];
}
else
{
GSCInlineString *o;
unsigned i;
o = (typeof(o))NSAllocateObject(GSCInlineStringClass,
_count, NSDefaultMallocZone());
o->_contents.c = (unsigned char*)
(((void*)o)+class_getInstanceSize(GSCInlineStringClass));
i = o->_count = _count;
while (i-- > 0)
{
o->_contents.c[i] = tolower(_contents.c[i]);
}
o->_flags.wide = 0;
o->_flags.owned = 1; // Ignored on dealloc, but means we own buffer
return [(id)o autorelease];
}
}
- (id) uppercaseString
{
if (_flags.wide == 1)
{
GSUnicodeInlineString *o;
unsigned i;
o = (typeof(o))NSAllocateObject(GSUnicodeInlineStringClass,
_count * sizeof(unichar), NSDefaultMallocZone());
o->_contents.u = (unichar*)
(((void*)o)+class_getInstanceSize(GSUnicodeInlineStringClass));
i = o->_count = _count;
while (i-- > 0)
{
o->_contents.u[i] = uni_toupper(_contents.u[i]);
}
o->_flags.wide = 1;
o->_flags.owned = 1; // Ignored on dealloc, but means we own buffer
return [(id)o autorelease];
}
else
{
GSCInlineString *o;
unsigned i;
o = (typeof(o))NSAllocateObject(GSCInlineStringClass,
_count, NSDefaultMallocZone());
o->_contents.c = (unsigned char*)
(((void*)o)+class_getInstanceSize(GSCInlineStringClass));
i = o->_count = _count;
while (i-- > 0)
{
o->_contents.c[i] = toupper(_contents.c[i]);
}
o->_flags.wide = 0;
o->_flags.owned = 1; // Ignored on dealloc, but means we own buffer
return [(id)o autorelease];
}
}
@end