Skip to content
Browse files

Merge pull request #62 from blackgold9/LoadOptimization

Calculation optimization. Don't need to calculate item positions every f...
  • Loading branch information...
2 parents 95f421a + 4da77fa commit 9ae7d4d25c84d388b08fff38c53a53940991b975 @gmoledina committed
Showing with 7 additions and 1 deletion.
  1. +7 −1 GMGridView/GMGridView.m
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));

0 comments on commit 9ae7d4d

Please sign in to comment.
Something went wrong with that request. Please try again.