Merge "Fixing widget size cache loop end-boundary" into tm-qpr-dev
diff --git a/src/com/android/launcher3/widget/picker/WidgetsRecyclerView.java b/src/com/android/launcher3/widget/picker/WidgetsRecyclerView.java
index 4c0e0d5..35fa7a4 100644
--- a/src/com/android/launcher3/widget/picker/WidgetsRecyclerView.java
+++ b/src/com/android/launcher3/widget/picker/WidgetsRecyclerView.java
@@ -173,11 +173,12 @@
     @Override
     protected int getItemsHeight(int untilIndex) {
         // Initialize cache
-        int childCount = Math.min(getChildCount(), getAdapter().getItemCount());
+        int childCount = getChildCount();
         int startPosition;
         if (childCount > 0
                 && ((startPosition = getChildAdapterPosition(getChildAt(0))) != NO_POSITION)) {
-            for (int i = 0; i < childCount; i++) {
+            int loopCount = Math.min(getChildCount(), getAdapter().getItemCount() - startPosition);
+            for (int i = 0; i < loopCount; i++) {
                 mCachedSizes.put(
                         mAdapter.getItemViewType(startPosition + i),
                         getChildAt(i).getMeasuredHeight());