Skip to content

Commit

Permalink
Calculation optimization. Don't need to calculate item positions ever…
Browse files Browse the repository at this point in the history
…y frame while scrolling.
  • Loading branch information
Stephen Vanterpool committed Mar 26, 2012
1 parent 95f421a commit 4da77fa
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 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));
Expand Down

0 comments on commit 4da77fa

Please sign in to comment.