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).
cleanup_build_scripts
tiatin 9 years ago
parent 93c2fd1989
commit 9b0422fc3c
  1. 6
      jme3-core/src/main/java/com/jme3/material/Material.java
  2. 7
      jme3-core/src/main/java/com/jme3/material/Technique.java

@ -751,10 +751,12 @@ public class Material implements CloneableSmartAsset, Cloneable, Savable {
private int applyOverrides(Renderer renderer, Shader shader, List<MatParamOverride> overrides, int unit) { private int applyOverrides(Renderer renderer, Shader shader, List<MatParamOverride> overrides, int unit) {
MatParamOverride override; MatParamOverride override;
boolean isArrayList = overrides instanceof ArrayList;
Iterator<MatParamOverride> 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++) { 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(); VarType type = override.getVarType();

@ -44,6 +44,7 @@ import com.jme3.shader.VarType;
import com.jme3.util.ListMap; import com.jme3.util.ListMap;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.EnumSet; import java.util.EnumSet;
import java.util.Iterator;
import java.util.List; import java.util.List;
/** /**
@ -112,10 +113,12 @@ public final class Technique {
private void applyOverrides(DefineList defineList, List<MatParamOverride> overrides) { private void applyOverrides(DefineList defineList, List<MatParamOverride> overrides) {
MatParamOverride override; MatParamOverride override;
boolean isArrayList = overrides instanceof ArrayList;
Iterator<MatParamOverride> 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++) { for (int i = 0, listSize = overrides.size(); i < listSize; i++) {
override = overrides.get(i); override = isArrayList ? overrides.get(i) : iterator.next();
if (!override.isEnabled()) { if (!override.isEnabled()) {
continue; continue;

Loading…
Cancel
Save