mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-31 16:50:58 +00:00
Use tiny strings in a few more places.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@35446 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
f2c68c13e4
commit
ccaefa05e8
1 changed files with 63 additions and 2 deletions
|
@ -755,6 +755,11 @@ static BOOL useTinyStrings;
|
||||||
@interface GSTinyString : NSString
|
@interface GSTinyString : NSString
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
static int tinyStrings = 0;
|
||||||
|
static void logTinyStringCount(void)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "%d tiny strings created\n", tinyStrings);
|
||||||
|
}
|
||||||
@implementation GSTinyString
|
@implementation GSTinyString
|
||||||
- (NSUInteger) length
|
- (NSUInteger) length
|
||||||
{
|
{
|
||||||
|
@ -783,6 +788,7 @@ static BOOL useTinyStrings;
|
||||||
+ (void) load
|
+ (void) load
|
||||||
{
|
{
|
||||||
useTinyStrings = objc_registerSmallObjectClass_np(self, TINY_STRING_MASK);
|
useTinyStrings = objc_registerSmallObjectClass_np(self, TINY_STRING_MASK);
|
||||||
|
atexit(logTinyStringCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (id) alloc
|
+ (id) alloc
|
||||||
|
@ -854,8 +860,11 @@ createTinyString(const char *str, int length)
|
||||||
s |= length << TINY_STRING_LENGTH_SHIFT;
|
s |= length << TINY_STRING_LENGTH_SHIFT;
|
||||||
for (i = 0 ; i<length ; i++)
|
for (i = 0 ; i<length ; i++)
|
||||||
{
|
{
|
||||||
|
// If this is not a 7-bit character, we can't use it.
|
||||||
|
if (str[i] & 0x80) { return nil; }
|
||||||
s |= ((uintptr_t)str[i]) << (57 - (i*7));
|
s |= ((uintptr_t)str[i]) << (57 - (i*7));
|
||||||
}
|
}
|
||||||
|
__sync_fetch_and_add(&tinyStrings, 1);
|
||||||
return (id)s;
|
return (id)s;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -3731,6 +3740,15 @@ agree, create a new GSCInlineString otherwise.
|
||||||
|
|
||||||
- (NSString*) substringFromRange: (NSRange)aRange
|
- (NSString*) substringFromRange: (NSRange)aRange
|
||||||
{
|
{
|
||||||
|
if (useTinyStrings && !_flags.wide)
|
||||||
|
{
|
||||||
|
id tinyString = createTinyString((char*)_contents.c + aRange.location, aRange.length);
|
||||||
|
|
||||||
|
if (tinyString)
|
||||||
|
{
|
||||||
|
return tinyString;
|
||||||
|
}
|
||||||
|
}
|
||||||
if (_flags.owned)
|
if (_flags.owned)
|
||||||
{
|
{
|
||||||
GS_RANGE_CHECK(aRange, _count);
|
GS_RANGE_CHECK(aRange, _count);
|
||||||
|
@ -3746,6 +3764,15 @@ agree, create a new GSCInlineString otherwise.
|
||||||
GS_RANGE_CHECK(aRange, _count);
|
GS_RANGE_CHECK(aRange, _count);
|
||||||
return substring_c((GSStr)self, aRange);
|
return substring_c((GSStr)self, aRange);
|
||||||
}
|
}
|
||||||
|
if (useTinyStrings && !_flags.wide)
|
||||||
|
{
|
||||||
|
id tinyString = createTinyString((char*)_contents.c + aRange.location, aRange.length);
|
||||||
|
|
||||||
|
if (tinyString)
|
||||||
|
{
|
||||||
|
return tinyString;
|
||||||
|
}
|
||||||
|
}
|
||||||
return [super substringWithRange: aRange];
|
return [super substringWithRange: aRange];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4048,6 +4075,15 @@ agree, create a new GSCInlineString otherwise.
|
||||||
|
|
||||||
- (NSString*) substringFromRange: (NSRange)aRange
|
- (NSString*) substringFromRange: (NSRange)aRange
|
||||||
{
|
{
|
||||||
|
if (useTinyStrings && !_flags.wide)
|
||||||
|
{
|
||||||
|
id tinyString = createTinyString((char*)_contents.c + aRange.location, aRange.length);
|
||||||
|
|
||||||
|
if (tinyString)
|
||||||
|
{
|
||||||
|
return tinyString;
|
||||||
|
}
|
||||||
|
}
|
||||||
if (_flags.owned)
|
if (_flags.owned)
|
||||||
{
|
{
|
||||||
GS_RANGE_CHECK(aRange, _count);
|
GS_RANGE_CHECK(aRange, _count);
|
||||||
|
@ -4058,6 +4094,15 @@ agree, create a new GSCInlineString otherwise.
|
||||||
|
|
||||||
- (NSString*) substringWithRange: (NSRange)aRange
|
- (NSString*) substringWithRange: (NSRange)aRange
|
||||||
{
|
{
|
||||||
|
if (useTinyStrings && !_flags.wide)
|
||||||
|
{
|
||||||
|
id tinyString = createTinyString((char*)_contents.c + aRange.location, aRange.length);
|
||||||
|
|
||||||
|
if (tinyString)
|
||||||
|
{
|
||||||
|
return tinyString;
|
||||||
|
}
|
||||||
|
}
|
||||||
if (_flags.owned)
|
if (_flags.owned)
|
||||||
{
|
{
|
||||||
GS_RANGE_CHECK(aRange, _count);
|
GS_RANGE_CHECK(aRange, _count);
|
||||||
|
@ -5062,7 +5107,15 @@ NSAssert(_flags.owned == 1 && _zone != 0, NSInternalInconsistencyException);
|
||||||
aRange.length * sizeof(unichar));
|
aRange.length * sizeof(unichar));
|
||||||
return o;
|
return o;
|
||||||
}
|
}
|
||||||
else
|
else if (useTinyStrings)
|
||||||
|
{
|
||||||
|
id tinyString = createTinyString((char*)_contents.c + aRange.location, aRange.length);
|
||||||
|
|
||||||
|
if (tinyString)
|
||||||
|
{
|
||||||
|
return tinyString;
|
||||||
|
}
|
||||||
|
}
|
||||||
{
|
{
|
||||||
GSCInlineString *o;
|
GSCInlineString *o;
|
||||||
|
|
||||||
|
@ -5089,7 +5142,15 @@ NSAssert(_flags.owned == 1 && _zone != 0, NSInternalInconsistencyException);
|
||||||
aRange.length * sizeof(unichar));
|
aRange.length * sizeof(unichar));
|
||||||
return o;
|
return o;
|
||||||
}
|
}
|
||||||
else
|
else if (useTinyStrings)
|
||||||
|
{
|
||||||
|
id tinyString = createTinyString((char*)_contents.c + aRange.location, aRange.length);
|
||||||
|
|
||||||
|
if (tinyString)
|
||||||
|
{
|
||||||
|
return tinyString;
|
||||||
|
}
|
||||||
|
}
|
||||||
{
|
{
|
||||||
GSCInlineString *o;
|
GSCInlineString *o;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue