mirror of
https://github.com/querydsl/querydsl.git
synced 2026-07-03 21:07:49 +08:00
#304 improved Normalization performance
This commit is contained in:
parent
8c0fc959e2
commit
02ef2c352d
@ -25,7 +25,11 @@ public final class Normalization {
|
||||
|
||||
private static final Pattern MULTIPLICATION = Pattern.compile(START + NUMBER + WS + "\\*" + WS + NUMBER);
|
||||
|
||||
public static final String normalize(String queryString) {
|
||||
public static final String normalize(String queryString) {
|
||||
if (!hasOperators(queryString)) {
|
||||
return queryString;
|
||||
}
|
||||
|
||||
StringBuilder rv = null;
|
||||
Matcher m = OPERATION.matcher(queryString);
|
||||
int end = 0;
|
||||
@ -74,8 +78,17 @@ public final class Normalization {
|
||||
}
|
||||
} else {
|
||||
return queryString;
|
||||
}
|
||||
}
|
||||
|
||||
private static final boolean hasOperators(String queryString) {
|
||||
for (int i = 0; i < queryString.length(); i++) {
|
||||
char ch = queryString.charAt(i);
|
||||
if (ch == '+' || ch == '-' || ch == '*' || ch == '/') {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private Normalization(){}
|
||||
|
||||
@ -5,6 +5,16 @@ import static org.junit.Assert.*;
|
||||
import org.junit.Test;
|
||||
|
||||
public class NormalizationTest {
|
||||
|
||||
@Test
|
||||
public void Performance() {
|
||||
int iterations = 1000000;
|
||||
long start = System.currentTimeMillis();
|
||||
for (int i = 0; i < iterations; i++) {
|
||||
Normalization.normalize("select name from companies where id = ?");
|
||||
}
|
||||
System.err.println(System.currentTimeMillis() - start);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void Variables() {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user