Skip to content

Commit

Permalink
Merge pull request #62 from blackgold9/LoadOptimization
Browse files Browse the repository at this point in the history
Calculation optimization. Don't need to calculate item positions every f...
  • Loading branch information
gmoledina committed Mar 27, 2012
2 parents 95f421a + 4da77fa commit 9ae7d4d
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion GMGridView/GMGridView.m
Expand Up @@ -1342,7 +1342,13 @@ - (void)loadRequiredItems
{ {
NSRange rangeOfPositions = [self.layoutStrategy rangeOfPositionsInBoundsFromOffset: self.contentOffset]; NSRange rangeOfPositions = [self.layoutStrategy rangeOfPositionsInBoundsFromOffset: self.contentOffset];
NSRange loadedPositionsRange = NSMakeRange(self.firstPositionLoaded, self.lastPositionLoaded - self.firstPositionLoaded); 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 // calculate new position range
self.firstPositionLoaded = self.firstPositionLoaded == GMGV_INVALID_POSITION ? rangeOfPositions.location : MIN(self.firstPositionLoaded, (NSInteger)rangeOfPositions.location); 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)); self.lastPositionLoaded = self.lastPositionLoaded == GMGV_INVALID_POSITION ? NSMaxRange(rangeOfPositions) : MAX(self.lastPositionLoaded, (NSInteger)(rangeOfPositions.length + rangeOfPositions.location));
Expand Down

0 comments on commit 9ae7d4d

Please sign in to comment.