Calculation optimization. Don't need to calculate item positions every f... #62

Merged
merged 1 commit into from Mar 27, 2012
View
8 GMGridView/GMGridView.m
@@ -1342,7 +1342,13 @@ - (void)loadRequiredItems
{
NSRange rangeOfPositions = [self.layoutStrategy rangeOfPositionsInBoundsFromOffset: self.contentOffset];
NSRange loadedPositionsRange = NSMakeRange(self.firstPositionLoaded, self.lastPositionLoaded - self.firstPositionLoaded);
-
+
+ if ((self.firstPositionLoaded != GMGV_INVALID_POSITION) &&
+ (self.lastPositionLoaded != GMGV_INVALID_POSITION) &&
+ NSEqualRanges(rangeOfPositions, loadedPositionsRange) ) {
+ return; // No need to load anything...
+ }
+
// calculate new position range
self.firstPositionLoaded = self.firstPositionLoaded == GMGV_INVALID_POSITION ? rangeOfPositions.location : MIN(self.firstPositionLoaded, (NSInteger)rangeOfPositions.location);
self.lastPositionLoaded = self.lastPositionLoaded == GMGV_INVALID_POSITION ? NSMaxRange(rangeOfPositions) : MAX(self.lastPositionLoaded, (NSInteger)(rangeOfPositions.length + rangeOfPositions.location));