From 9b0422fc3c56a952a60647a996bdd6c6e1db047f Mon Sep 17 00:00:00 2001 From: tiatin Date: Sat, 25 Jun 2016 18:15:03 +0300 Subject: [PATCH] Added iteration using iterator, if List is not ArrayList. Reason for this is that if List is LinkedList, complexity for get(int i) is O(n/4). --- jme3-core/src/main/java/com/jme3/material/Material.java | 6 ++++-- jme3-core/src/main/java/com/jme3/material/Technique.java | 7 +++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/jme3-core/src/main/java/com/jme3/material/Material.java b/jme3-core/src/main/java/com/jme3/material/Material.java index b66027e48..1b0150646 100644 --- a/jme3-core/src/main/java/com/jme3/material/Material.java +++ b/jme3-core/src/main/java/com/jme3/material/Material.java @@ -751,10 +751,12 @@ public class Material implements CloneableSmartAsset, Cloneable, Savable { private int applyOverrides(Renderer renderer, Shader shader, List overrides, int unit) { MatParamOverride override; + boolean isArrayList = overrides instanceof ArrayList; + Iterator iterator = isArrayList ? null : overrides.iterator(); - // manual iteration is used to avoid iterator allocation and to increase iteration performance + // manual iteration is used to avoid iterator allocation and to increase iteration performance in case of ArrayList for (int i = 0, listSize = overrides.size(); i < listSize; i++) { - override = overrides.get(i); + override = isArrayList ? overrides.get(i) : iterator.next(); VarType type = override.getVarType(); diff --git a/jme3-core/src/main/java/com/jme3/material/Technique.java b/jme3-core/src/main/java/com/jme3/material/Technique.java index 0fb7df93d..592629975 100644 --- a/jme3-core/src/main/java/com/jme3/material/Technique.java +++ b/jme3-core/src/main/java/com/jme3/material/Technique.java @@ -44,6 +44,7 @@ import com.jme3.shader.VarType; import com.jme3.util.ListMap; import java.util.ArrayList; import java.util.EnumSet; +import java.util.Iterator; import java.util.List; /** @@ -112,10 +113,12 @@ public final class Technique { private void applyOverrides(DefineList defineList, List overrides) { MatParamOverride override; + boolean isArrayList = overrides instanceof ArrayList; + Iterator iterator = isArrayList ? null : overrides.iterator(); - // manual iteration is used to avoid iterator allocation and to increase iteration performance + // manual iteration is used to avoid iterator allocation and to increase iteration performance in case of ArrayList for (int i = 0, listSize = overrides.size(); i < listSize; i++) { - override = overrides.get(i); + override = isArrayList ? overrides.get(i) : iterator.next(); if (!override.isEnabled()) { continue;