mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-22 16:33:29 +00:00
minor performance tweak
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@28237 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
067a687974
commit
4f5344d2c2
3 changed files with 66 additions and 6 deletions
|
@ -592,6 +592,51 @@ GSIMapNodeForKey(GSIMapTable map, GSIMapKey key)
|
|||
return node;
|
||||
}
|
||||
|
||||
static INLINE GSIMapNode
|
||||
GSIMapFirstNode(GSIMapTable map)
|
||||
{
|
||||
if (map->nodeCount > 0)
|
||||
{
|
||||
size_t count = map->bucketCount;
|
||||
size_t bucket = 0;
|
||||
GSIMapNode node = 0;
|
||||
|
||||
#if GS_WITH_GC
|
||||
if (GSI_MAP_ZEROED(map))
|
||||
{
|
||||
while (bucket < count)
|
||||
{
|
||||
node = map->buckets[bucket].firstNode;
|
||||
while (node != 0 && node->key.addr == 0)
|
||||
{
|
||||
node = GSIMapRemoveAndFreeNode(map, bucket, node);
|
||||
}
|
||||
if (node != 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
bucket++;
|
||||
}
|
||||
return node;
|
||||
}
|
||||
#endif
|
||||
while (bucket < count)
|
||||
{
|
||||
node = map->buckets[bucket].firstNode;
|
||||
if (node != 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
bucket++;
|
||||
}
|
||||
return node;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
#if (GSI_MAP_KTYPES & GSUNION_INT)
|
||||
/*
|
||||
* Specialized lookup for the case where keys are known to be simple integer
|
||||
|
|
|
@ -815,6 +815,13 @@ const NSHashTableCallBacks NSPointerToStructHashCallBacks =
|
|||
GSIMapTable t = (GSIMapTable)self;
|
||||
GSIMapNode n;
|
||||
|
||||
if (anObject == nil)
|
||||
{
|
||||
[NSException raise: NSInvalidArgumentException
|
||||
format: @"[%@-%@:] given nil argument",
|
||||
NSStringFromClass([self class]), NSStringFromSelector(_cmd)];
|
||||
}
|
||||
|
||||
n = GSIMapNodeForKey(t, (GSIMapKey)anObject);
|
||||
if (n == 0)
|
||||
{
|
||||
|
@ -849,6 +856,17 @@ const NSHashTableCallBacks NSPointerToStructHashCallBacks =
|
|||
return a;
|
||||
}
|
||||
|
||||
- (id) anyObject
|
||||
{
|
||||
GSIMapNode node = GSIMapFirstNode(self);
|
||||
|
||||
if (node == 0)
|
||||
{
|
||||
return nil;
|
||||
}
|
||||
return node->key.obj;
|
||||
}
|
||||
|
||||
- (id) copyWithZone: (NSZone*)aZone
|
||||
{
|
||||
return NSCopyHashTableWithZone(self, aZone);
|
||||
|
|
|
@ -1353,12 +1353,9 @@ const NSMapTableValueCallBacks NSOwnedPointerMapValueCallBacks =
|
|||
|
||||
if (aKey == nil)
|
||||
{
|
||||
NSException *e;
|
||||
|
||||
e = [NSException exceptionWithName: NSInvalidArgumentException
|
||||
reason: @"Tried to add nil key to map table"
|
||||
userInfo: nil];
|
||||
[e raise];
|
||||
[NSException raise: NSInvalidArgumentException
|
||||
format: @"[%@-%@:] given nil argument",
|
||||
NSStringFromClass([self class]), NSStringFromSelector(_cmd)];
|
||||
}
|
||||
node = GSIMapNodeForKey(self, (GSIMapKey)aKey);
|
||||
if (node)
|
||||
|
|
Loading…
Reference in a new issue