adium 2154:018ca7ad534b: Caching smallest/largest orders based o...

commits at adium.im commits at adium.im
Mon May 11 15:21:12 UTC 2009


details:	http://hg.adium.im/adium/rev/018ca7ad534b
revision:	2154:018ca7ad534b
author:		Zachary West <zacw at adium.im>
date:		Mon May 11 11:20:53 2009 -0400

Caching smallest/largest orders based on current-active objects ignores the ones not read in.

This caused us to assume that the smallest we've seen is the smallest, which is unlikely to be true if anything is not online. These misses were causing all worlds of trouble for reordering to the top (or bottom—though that was able to 'cleanly' recover) of anything.

Fixes #11888.

diffstat:

 Frameworks/Adium Framework/Source/AIListObject.h |   4 --
 Frameworks/Adium Framework/Source/AIListObject.m |  53 ++++++++++++++------------
 2 files changed, 28 insertions(+), 29 deletions(-)

diffs (105 lines):

diff -r 324a191f6542 -r 018ca7ad534b Frameworks/Adium Framework/Source/AIListObject.h
--- a/Frameworks/Adium Framework/Source/AIListObject.h	Mon May 11 02:25:40 2009 -0400
+++ b/Frameworks/Adium Framework/Source/AIListObject.h	Mon May 11 11:20:53 2009 -0400
@@ -88,10 +88,6 @@
 
 	//Grouping, Manual ordering
 	NSMutableSet *m_groups; //The AIContainingObjects that this object is in; currently always has only 1
-	
-	//For AIContainingObject-compliant subclasses
-	CGFloat					largestOrder;
-	CGFloat					smallestOrder;
 }
 
 - (id)initWithUID:(NSString *)inUID service:(AIService *)inService;
diff -r 324a191f6542 -r 018ca7ad534b Frameworks/Adium Framework/Source/AIListObject.m
--- a/Frameworks/Adium Framework/Source/AIListObject.m	Mon May 11 02:25:40 2009 -0400
+++ b/Frameworks/Adium Framework/Source/AIListObject.m	Mon May 11 11:20:53 2009 -0400
@@ -58,9 +58,6 @@
 
 		UID = [inUID retain];	
 		service = inService;
-
-		largestOrder = 1.0;
-		smallestOrder = 1.0;
 		
 		// Delay until the next run loop so bookmarks can instantiate their values first.
 		[self performSelector:@selector(setupObservedValues) withObject:nil afterDelay:0.0];
@@ -691,9 +688,9 @@
 	while (existingKeys.count && ![existingKeys isEqualToArray:[NSArray arrayWithObject:listObject.internalObjectID]]) {
 		if (existingKeys.count == 1) {
 			AILogWithSignature(@"*** Warning: %@ had order index %f, but %@ already had an object with that order index. Setting to %f instead. Incrementing.",
-							   listObject, orderIndexForObject, self, (largestOrder + 1));
+							   listObject, orderIndexForObject, self, (self.largestOrder + 1));
 
-			orderIndexForObject = ++largestOrder;
+			orderIndexForObject = self.largestOrder + 1;
 			orderIndexForObjectNumber = [NSNumber numberWithFloat:orderIndexForObject];
 			existingKeys = [dict allKeysForObject:orderIndexForObjectNumber];
 			
@@ -715,13 +712,6 @@
 	[self setPreference:newDict
 				 forKey:@"OrderIndexDictionary"
 				  group:ObjectStatusCache];
-	
-	//Keep track of our largest and smallest order indexes for quick access
-	if (orderIndexForObject > largestOrder) {
-		largestOrder = orderIndexForObject;
-	} else if (orderIndexForObject < smallestOrder) {
-		smallestOrder = orderIndexForObject;
-	}
 }
 
 //Order index
@@ -738,25 +728,38 @@
 	//XXX is this still needed?
 	if  (!(orderIndexForObject < INFINITY)) orderIndexForObject = 0;
 
-	if (orderIndexForObject) {
-		//Keep track of our largest and smallest order indexes for quick access
-		if (orderIndexForObject > largestOrder) {
-			largestOrder = orderIndexForObject;
-		} else if (orderIndexForObject < smallestOrder) {
-			smallestOrder = orderIndexForObject;
-		}
-		
-	} else {
-		//Assign it to our current largest order + 1
-		orderIndexForObject = ++largestOrder;
+	if (!orderIndexForObject) {
+		orderIndexForObject = self.largestOrder + 1;
 		[(AIListObject<AIContainingObject> *)self listObject:listObject didSetOrderIndex: orderIndexForObject];
 	}
 	
 	return orderIndexForObject;
 }
 
- at synthesize smallestOrder;
- at synthesize largestOrder;
+- (float)smallestOrder
+{
+	float smallest = INFINITY;
+	NSDictionary *orderIndex = [self preferenceForKey:@"OrderIndexDictionary" group:ObjectStatusCache];
+	
+	for (NSNumber *index in orderIndex.allValues) {
+		smallest = MIN(smallest, index.floatValue);
+	}
+	
+	return smallest;
+}
+
+- (float)largestOrder
+{
+	float largest = 0;
+	
+	NSDictionary *orderIndex = [self preferenceForKey:@"OrderIndexDictionary" group:ObjectStatusCache];
+	
+	for (NSNumber *index in orderIndex.allValues) {
+		largest = MAX(largest, index.floatValue);
+	}
+	
+	return largest;
+}
 
 #pragma mark Comparison
 /*


More information about the commits mailing list