Polish: replace the synchronized class "Stack" by an unsynchronized one such as "Deque".

This commit is contained in:
igor-suhorukov
2018-02-11 13:26:20 +03:00
committed by Juergen Hoeller
parent 3cbb2b7616
commit 711b0f50f2
8 changed files with 47 additions and 39 deletions

View File

@@ -16,9 +16,10 @@
package org.springframework.expression.common;
import java.util.ArrayDeque;
import java.util.LinkedList;
import java.util.List;
import java.util.Stack;
import java.util.Deque;
import org.springframework.expression.Expression;
import org.springframework.expression.ExpressionParser;
@@ -172,7 +173,7 @@ public abstract class TemplateAwareExpressionParser implements ExpressionParser
if (nextSuffix == -1) {
return -1; // the suffix is missing
}
Stack<Bracket> stack = new Stack<>();
Deque<Bracket> stack = new ArrayDeque<>();
while (pos < maxlen) {
if (isSuffixHere(expressionString, pos, suffix) && stack.isEmpty()) {
break;

View File

@@ -18,9 +18,10 @@ package org.springframework.expression.spel;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Deque;
import java.util.List;
import java.util.Stack;
import org.springframework.asm.ClassWriter;
import org.springframework.asm.MethodVisitor;
@@ -57,7 +58,7 @@ public class CodeFlow implements Opcodes {
* sub-expressions like the expressions for the argument values in a method invocation
* expression.
*/
private final Stack<ArrayList<String>> compilationScopes;
private final Deque<ArrayList<String>> compilationScopes;
/**
* As SpEL ast nodes are called to generate code for the main evaluation method
@@ -97,7 +98,7 @@ public class CodeFlow implements Opcodes {
public CodeFlow(String className, ClassWriter classWriter) {
this.className = className;
this.classWriter = classWriter;
this.compilationScopes = new Stack<>();
this.compilationScopes = new ArrayDeque<>();
this.compilationScopes.add(new ArrayList<String>());
}

View File

@@ -16,11 +16,13 @@
package org.springframework.expression.spel;
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.Stack;
import org.springframework.core.convert.TypeDescriptor;
import org.springframework.expression.EvaluationContext;
@@ -58,20 +60,20 @@ public class ExpressionState {
private final SpelParserConfiguration configuration;
@Nullable
private Stack<TypedValue> contextObjects;
private Deque<TypedValue> contextObjects;
@Nullable
private Stack<VariableScope> variableScopes;
private LinkedList<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).
// This stack captures those objects at each nested scope level.
// This ArrayDeque captures those objects at each nested scope level.
// For example:
// #list1.?[#list2.contains(#this)]
// On entering the selection we enter a new scope, and #this is now the
// element from list1
@Nullable
private Stack<TypedValue> scopeRootObjects;
private ArrayDeque<TypedValue> scopeRootObjects;
public ExpressionState(EvaluationContext context) {
@@ -107,14 +109,14 @@ public class ExpressionState {
public void pushActiveContextObject(TypedValue obj) {
if (this.contextObjects == null) {
this.contextObjects = new Stack<>();
this.contextObjects = new ArrayDeque<>();
}
this.contextObjects.push(obj);
}
public void popActiveContextObject() {
if (this.contextObjects == null) {
this.contextObjects = new Stack<>();
this.contextObjects = new ArrayDeque<>();
}
this.contextObjects.pop();
}
@@ -205,18 +207,18 @@ public class ExpressionState {
return null;
}
private Stack<VariableScope> initVariableScopes() {
private LinkedList<VariableScope> initVariableScopes() {
if (this.variableScopes == null) {
this.variableScopes = new Stack<>();
this.variableScopes = new LinkedList<>();
// top level empty variable scope
this.variableScopes.add(new VariableScope());
}
return this.variableScopes;
}
private Stack<TypedValue> initScopeRootObjects() {
private ArrayDeque<TypedValue> initScopeRootObjects() {
if (this.scopeRootObjects == null) {
this.scopeRootObjects = new Stack<>();
this.scopeRootObjects = new ArrayDeque<>();
}
return this.scopeRootObjects;
}

View File

@@ -16,11 +16,12 @@
package org.springframework.expression.spel.standard;
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.Stack;
import java.util.regex.Pattern;
import org.springframework.expression.ParseException;
@@ -93,7 +94,7 @@ class InternalSpelExpressionParser extends TemplateAwareExpressionParser {
private final SpelParserConfiguration configuration;
// For rules that build nodes, they are stacked here for return
private final Stack<SpelNodeImpl> constructedNodes = new Stack<>();
private final Deque<SpelNodeImpl> constructedNodes = new ArrayDeque<>();
// The expression being parsed
private String expressionString = "";