From: Fraser S. <fra...@us...> - 2004-10-05 20:22:06
|
Update of /cvsroot/ljkit/LJKit In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1864 Modified Files: LJAccount.h LJAccount_EditFriends.m Log Message: Performance fixes for -friendArray: and -groupArray: - avoid re-sorting the array every time it's called. This kills Xjournal. Index: LJAccount_EditFriends.m =================================================================== RCS file: /cvsroot/ljkit/LJKit/LJAccount_EditFriends.m,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** LJAccount_EditFriends.m 10 Jan 2004 08:35:23 -0000 1.2 --- LJAccount_EditFriends.m 5 Oct 2004 20:21:49 -0000 1.3 *************** *** 40,43 **** --- 40,49 ---- [_groupsSyncDate release]; _groupsSyncDate = [[NSDate alloc] init]; + + // Update the static ordered array cache + if(_orderedGroupArrayCache) { + [_orderedGroupArrayCache release]; + _orderedGroupArrayCache = [[[_groupSet allObjects] sortedArrayUsingSelector: @selector(compare:)] retain]; + } } *************** *** 95,98 **** --- 101,111 ---- [_friendsSyncDate release]; _friendsSyncDate = [[NSDate alloc] init]; + + if(_orderedFriendArrayCache) { + // The underlying set changed, so update the cache + [_orderedFriendArrayCache release]; + _orderedFriendArrayCache = [[[_friendSet allObjects] sortedArrayUsingSelector:@selector(compare:)] retain]; + } + return YES; } *************** *** 144,148 **** - (NSArray *)friendArray { ! return [[_friendSet allObjects] sortedArrayUsingSelector:@selector(compare:)]; } --- 157,166 ---- - (NSArray *)friendArray { ! // Lazily create the cache the first time it's needed ! if(!_orderedFriendArrayCache) ! _orderedFriendArrayCache = [[[_friendSet allObjects] sortedArrayUsingSelector:@selector(compare:)] retain]; ! ! // return the cached array ! return [[_orderedFriendArrayCache copy] autorelease]; } *************** *** 159,163 **** - (NSArray *)groupArray { ! return [[_groupSet allObjects] sortedArrayUsingSelector:@selector(compare:)]; } --- 177,184 ---- - (NSArray *)groupArray { ! if(!_orderedGroupArrayCache) ! _orderedGroupArrayCache = [[[_groupSet allObjects] sortedArrayUsingSelector: @selector(compare:)] retain]; ! ! return [[_orderedGroupArrayCache copy] autorelease]; //[[_groupSet allObjects] sortedArrayUsingSelector:@selector(compare:)]; } *************** *** 279,282 **** --- 300,310 ---- [_friendSet addObject:buddy]; [buddy release]; + + if(_orderedFriendArrayCache) { + // The underlying set changed, so change the cache + [_orderedFriendArrayCache release]; + _orderedFriendArrayCache = [[[_friendSet allObjects] sortedArrayUsingSelector:@selector(compare:)] retain]; + } + return buddy; } *************** *** 290,293 **** --- 318,326 ---- [_friendSet removeObject:buddy]; [buddy _setOutgoingFriendship:NO]; + + if(_orderedFriendArrayCache) { + [_orderedFriendArrayCache release]; + _orderedFriendArrayCache = [[[_friendSet allObjects] sortedArrayUsingSelector:@selector(compare:)] retain]; + } } *************** *** 307,310 **** --- 340,350 ---- [_groupSet addObject:group]; [group release]; + + // Update the static ordered array cache + if(_orderedGroupArrayCache) { + [_orderedGroupArrayCache release]; + _orderedGroupArrayCache = [[[_groupSet allObjects] sortedArrayUsingSelector: @selector(compare:)] retain]; + } + return group; } *************** *** 329,332 **** --- 369,378 ---- [group removeFriend:buddy]; } + + // Update the static ordered array cache + if(_orderedGroupArrayCache) { + [_orderedGroupArrayCache release]; + _orderedGroupArrayCache = [[[_groupSet allObjects] sortedArrayUsingSelector: @selector(compare:)] retain]; + } } Index: LJAccount.h =================================================================== RCS file: /cvsroot/ljkit/LJKit/LJAccount.h,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** LJAccount.h 28 Jul 2004 05:38:20 -0000 1.5 --- LJAccount.h 5 Oct 2004 20:21:49 -0000 1.6 *************** *** 169,172 **** --- 169,178 ---- NSDate *_groupsSyncDate; NSDate *_friendsSyncDate; + + // For efficiency, keep an ordered cache of friends, + // which we only update when _friendSet changes + NSArray *_orderedFriendArrayCache; + NSArray *_orderedGroupArrayCache; + // for internal linked list LJAccount *_nextAccount; |