]> source.dussan.org Git - vaadin-framework.git/commitdiff
Minor loop cleanup/optimization for #15443 fix
authorJohannes Dahlström <johannesd@vaadin.com>
Tue, 13 Jan 2015 10:21:53 +0000 (12:21 +0200)
committerVaadin Code Review <review@vaadin.com>
Wed, 14 Jan 2015 12:05:14 +0000 (12:05 +0000)
Change-Id: Iff6029865ab89f3738331edaa0673772414cb8ba

server/src/com/vaadin/data/RpcDataProviderExtension.java

index 2e6b4a8414c2e520e7aacecfa297d74982de4ace..2008988ce2e82d47e5758cb056c1853653d76d5a 100644 (file)
@@ -129,9 +129,8 @@ public class RpcDataProviderExtension extends AbstractExtension {
 
             List<?> newItemIds = container.getItemIds(added.getStart(),
                     added.length());
-
-            for (int i = 0; i < newItemIds.size(); i++) {
-
+            Integer index = added.getStart();
+            for (Object itemId : newItemIds) {
                 /*
                  * We might be in a situation we have an index <-> itemId entry
                  * already. This happens when something was selected, scrolled
@@ -139,27 +138,25 @@ public class RpcDataProviderExtension extends AbstractExtension {
                  * unnecessary to overwrite it in that case.
                  * 
                  * Fun thought: considering branch prediction, it _might_ even
-                 * be a bit faster to simply always run the code beyond this
+                 * be a bit faster to simply always run the code inside this
                  * if-state. But it sounds too stupid (and most often too
                  * insignificant) to try out.
                  */
-                final Integer index = Integer.valueOf(i + added.getStart());
-                if (indexToItemId.containsKey(index)) {
-                    continue;
-                }
+                if (!indexToItemId.containsKey(index)) {
+                    /*
+                     * We might be in a situation where we have an itemId <->
+                     * key entry already, but no index for it. This happens when
+                     * something that is out of view is selected
+                     * programmatically. In that case, we only want to add an
+                     * index for that entry, and not overwrite the key.
+                     */
+                    if (!itemIdToKey.containsKey(itemId)) {
+                        itemIdToKey.put(itemId, nextKey());
+                    }
 
-                /*
-                 * We might be in a situation where we have an itemId <-> key
-                 * entry already, but no index for it. This happens when
-                 * something that is out of view is selected programmatically.
-                 * In that case, we only want to add an index for that entry,
-                 * and not overwrite the key.
-                 */
-                final Object itemId = newItemIds.get(i);
-                if (!itemIdToKey.containsKey(itemId)) {
-                    itemIdToKey.put(itemId, nextKey());
+                    indexToItemId.forcePut(index, itemId);
                 }
-                indexToItemId.forcePut(index, itemId);
+                index++;
             }
         }