From 2ebaf7edb365ac95d10c6cb3c8c4e9bc62c526fa Mon Sep 17 00:00:00 2001 From: =?utf8?q?Johannes=20Dahlstr=C3=B6m?= Date: Tue, 13 Jan 2015 12:21:53 +0200 Subject: [PATCH] Minor loop cleanup/optimization for #15443 fix Change-Id: Iff6029865ab89f3738331edaa0673772414cb8ba --- .../vaadin/data/RpcDataProviderExtension.java | 35 +++++++++---------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/server/src/com/vaadin/data/RpcDataProviderExtension.java b/server/src/com/vaadin/data/RpcDataProviderExtension.java index 2e6b4a8414..2008988ce2 100644 --- a/server/src/com/vaadin/data/RpcDataProviderExtension.java +++ b/server/src/com/vaadin/data/RpcDataProviderExtension.java @@ -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++; } } -- 2.39.5