Avoid regex pattern matching for simple String replacement steps
Issue: SPR-17279
This commit is contained in:
@@ -19,6 +19,7 @@ package org.springframework.expression.spel.ast;
|
||||
import org.springframework.asm.MethodVisitor;
|
||||
import org.springframework.expression.TypedValue;
|
||||
import org.springframework.expression.spel.CodeFlow;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* Expression language AST node that represents a string literal.
|
||||
@@ -33,9 +34,13 @@ public class StringLiteral extends Literal {
|
||||
|
||||
|
||||
public StringLiteral(String payload, int pos, String value) {
|
||||
super(payload,pos);
|
||||
value = value.substring(1, value.length() - 1);
|
||||
this.value = new TypedValue(value.replaceAll("''", "'").replaceAll("\"\"", "\""));
|
||||
super(payload, pos);
|
||||
|
||||
String valueWithinQuotes = value.substring(1, value.length() - 1);
|
||||
valueWithinQuotes = StringUtils.replace(valueWithinQuotes, "''", "'");
|
||||
valueWithinQuotes = StringUtils.replace(valueWithinQuotes, "\"\"", "\"");
|
||||
|
||||
this.value = new TypedValue(valueWithinQuotes);
|
||||
this.exitTypeDescriptor = "Ljava/lang/String";
|
||||
}
|
||||
|
||||
|
||||
@@ -36,6 +36,7 @@ import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.ClassUtils;
|
||||
import org.springframework.util.ConcurrentReferenceHashMap;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* A SpelCompiler will take a regular parsed expression and create (and load) a class
|
||||
@@ -132,9 +133,9 @@ public final class SpelCompiler implements Opcodes {
|
||||
@Nullable
|
||||
private Class<? extends CompiledExpression> createExpressionClass(SpelNodeImpl expressionToCompile) {
|
||||
// Create class outline 'spel/ExNNN extends org.springframework.expression.spel.CompiledExpression'
|
||||
String clazzName = "spel/Ex" + getNextSuffix();
|
||||
String className = "spel/Ex" + getNextSuffix();
|
||||
ClassWriter cw = new ExpressionClassWriter();
|
||||
cw.visit(V1_5, ACC_PUBLIC, clazzName, null, "org/springframework/expression/spel/CompiledExpression", null);
|
||||
cw.visit(V1_5, ACC_PUBLIC, className, null, "org/springframework/expression/spel/CompiledExpression", null);
|
||||
|
||||
// Create default constructor
|
||||
MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
|
||||
@@ -152,7 +153,7 @@ public final class SpelCompiler implements Opcodes {
|
||||
new String[ ]{"org/springframework/expression/EvaluationException"});
|
||||
mv.visitCode();
|
||||
|
||||
CodeFlow cf = new CodeFlow(clazzName, cw);
|
||||
CodeFlow cf = new CodeFlow(className, cw);
|
||||
|
||||
// Ask the expression AST to generate the body of the method
|
||||
try {
|
||||
@@ -181,7 +182,7 @@ public final class SpelCompiler implements Opcodes {
|
||||
byte[] data = cw.toByteArray();
|
||||
// TODO need to make this conditionally occur based on a debug flag
|
||||
// dump(expressionToCompile.toStringAST(), clazzName, data);
|
||||
return loadClass(clazzName.replaceAll("/", "."), data);
|
||||
return loadClass(StringUtils.replace(className, "/", "."), data);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user