summaryrefslogtreecommitdiffstats
path: root/server/src/com/vaadin/data/RpcDataProviderExtension.java
diff options
context:
space:
mode:
authorJohannes Dahlström <johannesd@vaadin.com>2015-01-13 12:21:53 +0200
committerVaadin Code Review <review@vaadin.com>2015-01-14 12:05:14 +0000
commit2ebaf7edb365ac95d10c6cb3c8c4e9bc62c526fa (patch)
treea09ff974c9ffd6cdfd112c38951df2fa0d31eb10 /server/src/com/vaadin/data/RpcDataProviderExtension.java
parent67090d9229707af3246eecc2ea56ad68e138772f (diff)
downloadvaadin-framework-2ebaf7edb365ac95d10c6cb3c8c4e9bc62c526fa.tar.gz
vaadin-framework-2ebaf7edb365ac95d10c6cb3c8c4e9bc62c526fa.zip
Minor loop cleanup/optimization for #15443 fix
Change-Id: Iff6029865ab89f3738331edaa0673772414cb8ba
Diffstat (limited to 'server/src/com/vaadin/data/RpcDataProviderExtension.java')
-rw-r--r--server/src/com/vaadin/data/RpcDataProviderExtension.java35
1 files 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++;
}
}