check for nil

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@37318 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
rfm 2013-10-29 15:31:24 +00:00
parent 07152c53ae
commit 5ecbbfe3bb

View file

@ -132,25 +132,29 @@ static IMP unlockImp;
static NSDictionary* static NSDictionary*
cacheAttributes(NSDictionary *attrs) cacheAttributes(NSDictionary *attrs)
{ {
GSIMapNode node; if (nil != attrs)
{
GSIMapNode node;
ALOCK(); ALOCK();
node = GSIMapNodeForKey(&attrMap, (GSIMapKey)((id)attrs)); node = GSIMapNodeForKey(&attrMap, (GSIMapKey)((id)attrs));
if (node == 0) if (node == 0)
{ {
/* /* Shallow copy of dictionary, without copying objects ....
* Shallow copy of dictionary, without copying objects ... results * result in an immutable dictionary that can safely be cached.
* in an immutable dictionary that can safely be cached. */
*/ attrs = [[NSDictionary alloc] initWithDictionary: attrs
attrs = [[NSDictionary alloc] initWithDictionary: attrs copyItems: NO]; copyItems: NO];
GSIMapAddPair(&attrMap, (GSIMapKey)((id)attrs), (GSIMapVal)(NSUInteger)1); GSIMapAddPair(&attrMap,
(GSIMapKey)((id)attrs), (GSIMapVal)(NSUInteger)1);
}
else
{
node->value.nsu++;
attrs = RETAIN(node->key.obj);
}
AUNLOCK();
} }
else
{
node->value.nsu++;
attrs = RETAIN(node->key.obj);
}
AUNLOCK();
return attrs; return attrs;
} }
@ -160,30 +164,34 @@ cacheAttributes(NSDictionary *attrs)
static void static void
unCacheAttributes(NSDictionary *attrs) unCacheAttributes(NSDictionary *attrs)
{ {
GSIMapBucket bucket; if (nil != attrs)
NSDictionary *found;
found = nil;
ALOCK();
bucket = GSIMapBucketForKey(&attrMap, (GSIMapKey)((id)attrs));
if (bucket != 0)
{ {
GSIMapNode node; GSIMapBucket bucket;
NSDictionary *found;
node = GSIMapNodeForKeyInBucket(&attrMap, bucket, (GSIMapKey)((id)attrs)); found = nil;
if (node != 0) ALOCK();
{ bucket = GSIMapBucketForKey(&attrMap, (GSIMapKey)((id)attrs));
found = node->key.obj; if (bucket != 0)
if (--node->value.nsu == 0) {
{ GSIMapNode node;
GSIMapRemoveNodeFromMap(&attrMap, bucket, node);
GSIMapFreeNode(&attrMap, node); node = GSIMapNodeForKeyInBucket(&attrMap,
} bucket, (GSIMapKey)((id)attrs));
} if (node != 0)
{
found = node->key.obj;
if (--node->value.nsu == 0)
{
GSIMapRemoveNodeFromMap(&attrMap, bucket, node);
GSIMapFreeNode(&attrMap, node);
}
}
}
AUNLOCK();
NSCAssert(found == attrs, NSInternalInconsistencyException);
RELEASE(found);
} }
AUNLOCK();
NSCAssert(found == attrs, NSInternalInconsistencyException);
RELEASE(found);
} }