Improve dictionary lookup for strings.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@3003 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-MacDonald 1998-10-01 05:22:47 +00:00
parent c4337b9ca9
commit 1601128ae7
4 changed files with 80 additions and 5 deletions

View file

@ -267,16 +267,48 @@ static Class mutableClass;
return [NSString defaultCStringEncoding];
}
- (BOOL) isEqual: (id)anObject
{
Class c;
if (anObject == self)
return YES;
c = ((NSGCString*)anObject)->isa; /* Hack. */
if (c == immutableClass || c == mutableClass)
{
NSGCString *other = (NSGCString*)anObject;
if (_count != other->_count)
return NO;
if (_hash == 0)
if ((_hash = [super hash]) == 0)
_hash = 0xffffffff;
if (other->_hash == 0) [other hash];
if (_hash != other->_hash)
return NO;
if (memcmp(_contents_chars, other->_contents_chars, _count) != 0)
return NO;
return YES;
}
else if ([c isKindOfClass: [NSString class]])
return [super isEqualToString: (NSString*)anObject];
else
return [super isEqual: anObject];
}
- (BOOL) isEqualToString: (NSString*)aString
{
Class c = [aString class];
Class c;
c = ((NSGCString*)aString)->isa; /* Hack. */
if (c == immutableClass || c == mutableClass)
{
NSGCString *other = (NSGCString*)aString;
if (_count != other->_count)
return NO;
if (_hash && other->_hash && (_hash != other->_hash))
if (_hash == 0) [self hash];
if (other->_hash == 0) [other hash];
if (_hash != other->_hash)
return NO;
if (memcmp(_contents_chars, other->_contents_chars, _count) != 0)
return NO;
@ -284,7 +316,6 @@ static Class mutableClass;
}
else
return [super isEqualToString: aString];
return YES;
}

View file

@ -43,6 +43,20 @@
@implementation NSGString
static Class immutableClass;
static Class mutableClass;
+ (void) initialize
{
static int done = 0;
if (!done)
{
done = 1;
immutableClass = [NSGString class];
mutableClass = [NSGMutableString class];
}
}
- (void)dealloc
{
if (_free_contents)
@ -61,6 +75,26 @@
return _hash;
}
- (BOOL) isEqual: (id)anObject
{
Class c;
if (anObject == self)
return YES;
c = [anObject class];
if (c == immutableClass || c == mutableClass)
{
NSGString *other = (NSGString*)anObject;
if (_hash == 0) [self hash];
if (other->_hash == 0) [other hash];
if (_hash != other->_hash)
return NO;
return [self isEqualToString: other];
}
else
return [super isEqual: anObject];
}
// Initializing Newly Allocated Strings
/* This is the designated initializer for this class. */

View file

@ -1406,7 +1406,7 @@ else
{
if (anObject == self)
return YES;
if ([anObject isKindOf:[NSString class]])
if ([anObject isKindOfClass:[NSString class]] == YES)
return [self isEqualToString:anObject];
return NO;
}

View file

@ -562,12 +562,22 @@ o_map_key_at_key(o_map_t *map, const void *key)
const void *
o_map_value_at_key(o_map_t *map, const void *key)
{
#if 0
const void *value;
/* Use the grandfather function above... */
o_map_key_and_value_at_key(map, 0, &value, key);
return value;
#else
o_map_node_t *node;
/* Try and find the node for KEY. */
node = _o_map_node_for_key(map, key);
if (node != 0)
return node->value;
return 0;
#endif
}
const void **