Browse files

HHH-7869 bad performance problem with org.hibernate.internal.util.Str…

…ingHelper#firstIndexOfChar
  • Loading branch information...
1 parent 941579d commit 8850c1fa912da43832a9ba968dc41f4a6ed49f9e @stliu stliu committed Dec 17, 2012
View
7 hibernate-core/src/main/java/org/hibernate/hql/internal/classic/ParserHelper.java
@@ -23,6 +23,7 @@
*
*/
package org.hibernate.hql.internal.classic;
+import java.util.BitSet;
import java.util.StringTokenizer;
import org.hibernate.QueryException;
@@ -33,6 +34,12 @@
public static final String HQL_VARIABLE_PREFIX = ":";
public static final String HQL_SEPARATORS = " \n\r\f\t,()=<>&|+-=/*'^![]#~\\";
+ public static final BitSet HQL_SEPARATORS_BITSET = new BitSet( );
+ static {
+ for(int i=0;i<HQL_SEPARATORS.length();i++){
+ HQL_SEPARATORS_BITSET.set( HQL_SEPARATORS.charAt( i ) );
+ }
+ }
//NOTICE: no " or . since they are part of (compound) identifiers
public static final String PATH_SEPARATORS = ".";
View
27 hibernate-core/src/main/java/org/hibernate/internal/util/StringHelper.java
@@ -27,6 +27,7 @@
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.BitSet;
import java.util.Iterator;
import java.util.StringTokenizer;
import java.util.UUID;
@@ -472,21 +473,23 @@ public static String qualify(String prefix, String name) {
}
return qualified;
}
+ public static int firstIndexOfChar(String sqlString, BitSet keys, int startindex) {
+ for ( int i = startindex, size = sqlString.length(); i < size; i++ ) {
+ if ( keys.get( sqlString.charAt( i ) ) ) {
+ return i;
+ }
+ }
+ return -1;
+
+ }
public static int firstIndexOfChar(String sqlString, String string, int startindex) {
- int matchAt = -1;
- for ( int i = 0; i < string.length(); i++ ) {
- int curMatch = sqlString.indexOf( string.charAt( i ), startindex );
- if ( curMatch >= 0 ) {
- if ( matchAt == -1 ) { // first time we find match!
- matchAt = curMatch;
- }
- else {
- matchAt = Math.min( matchAt, curMatch );
- }
- }
+ BitSet keys = new BitSet();
+ for ( int i = 0, size = string.length(); i < size; i++ ) {
+ keys.set( string.charAt( i ) );
}
- return matchAt;
+ return firstIndexOfChar( sqlString, keys, startindex );
+
}
public static String truncate(String string, int length) {

0 comments on commit 8850c1f

Please sign in to comment.