Prefer ArrayList/ArrayDeque over LinkedList for multi-element holders

LinkedList remains in place where a List is likely to remain empty or single-element (in order to avoid unused capacity).

Issue: SPR-17037

(cherry picked from commit 9c08a48)
This commit is contained in:
Juergen Hoeller
2018-07-18 22:17:42 +02:00
parent ed54895e53
commit 11fc086309
27 changed files with 119 additions and 125 deletions

View File

@@ -17,8 +17,8 @@
package org.springframework.expression.common;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Deque;
import java.util.LinkedList;
import java.util.List;
import org.springframework.expression.Expression;
@@ -87,7 +87,7 @@ public abstract class TemplateAwareExpressionParser implements ExpressionParser
* @throws ParseException when the expressions cannot be parsed
*/
private Expression[] parseExpressions(String expressionString, ParserContext context) throws ParseException {
List<Expression> expressions = new LinkedList<>();
List<Expression> expressions = new ArrayList<>();
String prefix = context.getExpressionPrefix();
String suffix = context.getExpressionSuffix();
int startIdx = 0;

View File

@@ -20,7 +20,6 @@ import java.util.ArrayDeque;
import java.util.Collections;
import java.util.Deque;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.NoSuchElementException;
@@ -65,7 +64,7 @@ public class ExpressionState {
private Deque<TypedValue> contextObjects;
@Nullable
private LinkedList<VariableScope> variableScopes;
private Deque<VariableScope> variableScopes;
// When entering a new scope there is a new base object which should be used
// for '#this' references (or to act as a target for unqualified references).
@@ -215,7 +214,7 @@ public class ExpressionState {
private Deque<VariableScope> initVariableScopes() {
if (this.variableScopes == null) {
this.variableScopes = new LinkedList<>();
this.variableScopes = new ArrayDeque<>();
// top-level empty variable scope
this.variableScopes.add(new VariableScope());
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,7 +17,6 @@
package org.springframework.expression.spel.ast;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import org.springframework.expression.PropertyAccessor;
@@ -68,7 +67,7 @@ public abstract class AstUtils {
}
}
}
List<PropertyAccessor> resolvers = new LinkedList<>();
List<PropertyAccessor> resolvers = new ArrayList<>(specificAccessors.size() + generalAccessors.size());
resolvers.addAll(specificAccessors);
resolvers.addAll(generalAccessors);
return resolvers;

View File

@@ -20,7 +20,6 @@ import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Deque;
import java.util.LinkedList;
import java.util.List;
import java.util.regex.Pattern;
@@ -456,7 +455,7 @@ class InternalSpelExpressionParser extends TemplateAwareExpressionParser {
}
/**
* Used for consuming arguments for either a method or a constructor call
* Used for consuming arguments for either a method or a constructor call.
*/
private void consumeArguments(List<SpelNodeImpl> accumulatedArguments) {
Token t = peekToken();
@@ -724,7 +723,7 @@ class InternalSpelExpressionParser extends TemplateAwareExpressionParser {
* TODO AndyC Could create complete identifiers (a.b.c) here rather than a sequence of them? (a, b, c)
*/
private SpelNodeImpl eatPossiblyQualifiedId() {
LinkedList<SpelNodeImpl> qualifiedIdPieces = new LinkedList<>();
Deque<SpelNodeImpl> qualifiedIdPieces = new ArrayDeque<>();
Token node = peekToken();
while (isValidQualifiedId(node)) {
nextToken();