Implement fast enumeration for insensitive dictionary

This commit is contained in:
Richard Frith-Macdonald 2020-09-08 15:14:19 +01:00
parent 7dc4a8f532
commit 938f280b87
2 changed files with 26 additions and 1 deletions

View file

@ -61,6 +61,7 @@
{
@public
GSIMapTable_t map;
NSUInteger _version;
}
@end
@ -349,6 +350,15 @@ static SEL objSel;
return nil;
}
- (NSUInteger) countByEnumeratingWithState: (NSFastEnumerationState*)state
objects: (__unsafe_unretained id[])stackbuf
count: (NSUInteger)len
{
state->mutationsPtr = (unsigned long *)self;
return GSIMapCountByEnumeratingWithStateObjectsCount
(&map, state, stackbuf, len);
}
@end
@implementation _GSMutableInsensitiveDictionary
@ -396,6 +406,7 @@ static SEL objSel;
{
GSIMapNode node;
_version++;
if (aKey == nil)
{
NSException *e;
@ -425,11 +436,14 @@ static SEL objSel;
{
GSIMapAddPair(&map, (GSIMapKey)aKey, (GSIMapVal)anObject);
}
_version++;
}
- (void) removeAllObjects
{
_version++;
GSIMapCleanMap(&map);
_version++;
}
- (void) removeObjectForKey: (id)aKey
@ -439,7 +453,18 @@ static SEL objSel;
NSWarnMLog(@"attempt to remove nil key from dictionary %@", self);
return;
}
_version++;
GSIMapRemoveKey(&map, (GSIMapKey)aKey);
_version++;
}
- (NSUInteger) countByEnumeratingWithState: (NSFastEnumerationState*)state
objects: (__unsafe_unretained id[])stackbuf
count: (NSUInteger)len
{
state->mutationsPtr = (unsigned long *)&_version;
return GSIMapCountByEnumeratingWithStateObjectsCount
(&map, state, stackbuf, len);
}
@end

View file

@ -426,7 +426,6 @@ static SEL objSel;
{
GSIMapNode node;
_version++;
if (aKey == nil)
{
NSException *e;
@ -448,6 +447,7 @@ static SEL objSel;
userInfo: self];
[e raise];
}
_version++;
node = GSIMapNodeForKey(&map, (GSIMapKey)aKey);
if (node)
{