mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-31 16:50:58 +00:00
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:
parent
40af9def9d
commit
38796b2e68
4 changed files with 80 additions and 5 deletions
|
@ -267,16 +267,48 @@ static Class mutableClass;
|
||||||
return [NSString defaultCStringEncoding];
|
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
|
- (BOOL) isEqualToString: (NSString*)aString
|
||||||
{
|
{
|
||||||
Class c = [aString class];
|
Class c;
|
||||||
|
|
||||||
|
c = ((NSGCString*)aString)->isa; /* Hack. */
|
||||||
if (c == immutableClass || c == mutableClass)
|
if (c == immutableClass || c == mutableClass)
|
||||||
{
|
{
|
||||||
NSGCString *other = (NSGCString*)aString;
|
NSGCString *other = (NSGCString*)aString;
|
||||||
|
|
||||||
if (_count != other->_count)
|
if (_count != other->_count)
|
||||||
return NO;
|
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;
|
return NO;
|
||||||
if (memcmp(_contents_chars, other->_contents_chars, _count) != 0)
|
if (memcmp(_contents_chars, other->_contents_chars, _count) != 0)
|
||||||
return NO;
|
return NO;
|
||||||
|
@ -284,7 +316,6 @@ static Class mutableClass;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
return [super isEqualToString: aString];
|
return [super isEqualToString: aString];
|
||||||
return YES;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -43,6 +43,20 @@
|
||||||
|
|
||||||
@implementation NSGString
|
@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
|
- (void)dealloc
|
||||||
{
|
{
|
||||||
if (_free_contents)
|
if (_free_contents)
|
||||||
|
@ -61,6 +75,26 @@
|
||||||
return _hash;
|
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
|
// Initializing Newly Allocated Strings
|
||||||
|
|
||||||
/* This is the designated initializer for this class. */
|
/* This is the designated initializer for this class. */
|
||||||
|
|
|
@ -1406,7 +1406,7 @@ else
|
||||||
{
|
{
|
||||||
if (anObject == self)
|
if (anObject == self)
|
||||||
return YES;
|
return YES;
|
||||||
if ([anObject isKindOf:[NSString class]])
|
if ([anObject isKindOfClass:[NSString class]] == YES)
|
||||||
return [self isEqualToString:anObject];
|
return [self isEqualToString:anObject];
|
||||||
return NO;
|
return NO;
|
||||||
}
|
}
|
||||||
|
|
|
@ -562,12 +562,22 @@ o_map_key_at_key(o_map_t *map, const void *key)
|
||||||
const void *
|
const void *
|
||||||
o_map_value_at_key(o_map_t *map, const void *key)
|
o_map_value_at_key(o_map_t *map, const void *key)
|
||||||
{
|
{
|
||||||
|
#if 0
|
||||||
const void *value;
|
const void *value;
|
||||||
|
|
||||||
/* Use the grandfather function above... */
|
/* Use the grandfather function above... */
|
||||||
o_map_key_and_value_at_key(map, 0, &value, key);
|
o_map_key_and_value_at_key(map, 0, &value, key);
|
||||||
|
|
||||||
return value;
|
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 **
|
const void **
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue