Change -objectForKey: method to get the contents into a buffer (on the stack) and iterate through them rather than creating an autoreleased enumerator. This avoids allocation/autorelease/deallocation of the enumerator (as well as etain/release of the search list by the enumerator) which should give better performance generally and avoid excess object creation when lots of defaults lookups are done in an autorelease pool.

This commit is contained in:
Richard Frith-Macdonald 2020-06-03 14:48:22 +01:00
parent bf4c0719aa
commit a1d5d020b3

View file

@ -1354,24 +1354,23 @@ newLanguages(NSArray *oldNames)
- (id) objectForKey: (NSString*)defaultName
{
NSEnumerator *enumerator;
IMP nImp;
id object = nil;
id dN;
IMP pImp;
IMP tImp;
id object = nil;
[_lock lock];
NS_DURING
{
enumerator = [_searchList objectEnumerator];
nImp = [enumerator methodForSelector: nextObjectSel];
object = nil;
NSUInteger count = [_searchList count];
IMP pImp;
IMP tImp;
NSUInteger index;
GS_BEGINITEMBUF(items, count, NSObject*)
pImp = [_persDomains methodForSelector: objectForKeySel];
tImp = [_tempDomains methodForSelector: objectForKeySel];
while ((dN = (*nImp)(enumerator, nextObjectSel)) != nil)
{
[_searchList getObjects: items];
for (index = 0; index < count; index++)
{
NSObject *dN = items[index];
GSPersistentDomain *pd;
NSDictionary *td;
@ -1383,6 +1382,7 @@ newLanguages(NSArray *oldNames)
break;
}
RETAIN(object);
GS_ENDITEMBUF();
[_lock unlock];
}
NS_HANDLER