Polish: replace the synchronized class "Stack" by an unsynchronized one such as "Deque".
This commit is contained in:
parent
3cbb2b7616
commit
711b0f50f2
|
@ -16,13 +16,13 @@
|
|||
|
||||
package org.springframework.beans.factory.parsing;
|
||||
|
||||
import java.util.Stack;
|
||||
import java.util.LinkedList;
|
||||
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
/**
|
||||
* Simple {@link Stack}-based structure for tracking the logical position during
|
||||
* a parsing process. {@link Entry entries} are added to the stack at
|
||||
* Simple {@link LinkedList}-based structure for tracking the logical position during
|
||||
* a parsing process. {@link Entry entries} are added to the LinkedList at
|
||||
* each point during the parse phase in a reader-specific manner.
|
||||
*
|
||||
* <p>Calling {@link #toString()} will render a tree-style view of the current logical
|
||||
|
@ -40,49 +40,49 @@ public final class ParseState {
|
|||
private static final char TAB = '\t';
|
||||
|
||||
/**
|
||||
* Internal {@link Stack} storage.
|
||||
* Internal {@link LinkedList} storage.
|
||||
*/
|
||||
private final Stack<Entry> state;
|
||||
private final LinkedList<Entry> state;
|
||||
|
||||
|
||||
/**
|
||||
* Create a new {@code ParseState} with an empty {@link Stack}.
|
||||
* Create a new {@code ParseState} with an empty {@link LinkedList}.
|
||||
*/
|
||||
public ParseState() {
|
||||
this.state = new Stack<>();
|
||||
this.state = new LinkedList<>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new {@code ParseState} whose {@link Stack} is a {@link Object#clone clone}
|
||||
* Create a new {@code ParseState} whose {@link LinkedList} is a {@link Object#clone clone}
|
||||
* of that of the passed in {@code ParseState}.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
private ParseState(ParseState other) {
|
||||
this.state = (Stack<Entry>) other.state.clone();
|
||||
this.state = (LinkedList<Entry>) other.state.clone();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add a new {@link Entry} to the {@link Stack}.
|
||||
* Add a new {@link Entry} to the {@link LinkedList}.
|
||||
*/
|
||||
public void push(Entry entry) {
|
||||
this.state.push(entry);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove an {@link Entry} from the {@link Stack}.
|
||||
* Remove an {@link Entry} from the {@link LinkedList}.
|
||||
*/
|
||||
public void pop() {
|
||||
this.state.pop();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the {@link Entry} currently at the top of the {@link Stack} or
|
||||
* {@code null} if the {@link Stack} is empty.
|
||||
* Return the {@link Entry} currently at the top of the {@link LinkedList} or
|
||||
* {@code null} if the {@link LinkedList} is empty.
|
||||
*/
|
||||
@Nullable
|
||||
public Entry peek() {
|
||||
return this.state.empty() ? null : this.state.peek();
|
||||
return this.state.isEmpty() ? null : this.state.peek();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -16,7 +16,8 @@
|
|||
|
||||
package org.springframework.beans.factory.xml;
|
||||
|
||||
import java.util.Stack;
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.Deque;
|
||||
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.beans.factory.parsing.BeanComponentDefinition;
|
||||
|
@ -46,7 +47,7 @@ public final class ParserContext {
|
|||
@Nullable
|
||||
private BeanDefinition containingBeanDefinition;
|
||||
|
||||
private final Stack<ComponentDefinition> containingComponents = new Stack<>();
|
||||
private final Deque<ComponentDefinition> containingComponents = new ArrayDeque<>();
|
||||
|
||||
|
||||
public ParserContext(XmlReaderContext readerContext, BeanDefinitionParserDelegate delegate) {
|
||||
|
@ -96,7 +97,7 @@ public final class ParserContext {
|
|||
@Nullable
|
||||
public CompositeComponentDefinition getContainingComponent() {
|
||||
return (!this.containingComponents.isEmpty() ?
|
||||
(CompositeComponentDefinition) this.containingComponents.lastElement() : null);
|
||||
(CompositeComponentDefinition) this.containingComponents.getLast() : null);
|
||||
}
|
||||
|
||||
public void pushContainingComponent(CompositeComponentDefinition containingComponent) {
|
||||
|
|
|
@ -17,11 +17,12 @@
|
|||
package org.springframework.validation;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.Collections;
|
||||
import java.util.Deque;
|
||||
import java.util.EmptyStackException;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Stack;
|
||||
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
@ -40,7 +41,7 @@ public abstract class AbstractErrors implements Errors, Serializable {
|
|||
|
||||
private String nestedPath = "";
|
||||
|
||||
private final Stack<String> nestedPathStack = new Stack<>();
|
||||
private final Deque<String> nestedPathStack = new ArrayDeque<>();
|
||||
|
||||
|
||||
@Override
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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>());
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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 = "";
|
||||
|
|
|
@ -18,7 +18,8 @@ package org.springframework.web.servlet.tags.form;
|
|||
|
||||
import java.io.IOException;
|
||||
import java.io.Writer;
|
||||
import java.util.Stack;
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.Deque;
|
||||
|
||||
import javax.servlet.jsp.JspException;
|
||||
import javax.servlet.jsp.PageContext;
|
||||
|
@ -46,7 +47,7 @@ public class TagWriter {
|
|||
/**
|
||||
* Stores {@link TagStateEntry tag state}. Stack model naturally supports tag nesting.
|
||||
*/
|
||||
private final Stack<TagStateEntry> tagState = new Stack<>();
|
||||
private final Deque<TagStateEntry> tagState = new ArrayDeque<>();
|
||||
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue