mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
improve performance
This commit is contained in:
@@ -26,6 +26,7 @@ import java.util.Map;
|
||||
import com.alibaba.druid.sql.parser.Keywords;
|
||||
import com.alibaba.druid.sql.parser.Lexer;
|
||||
import com.alibaba.druid.sql.parser.NotAllowCommentException;
|
||||
import com.alibaba.druid.sql.parser.ParserException;
|
||||
import com.alibaba.druid.sql.parser.SQLParseException;
|
||||
import com.alibaba.druid.sql.parser.Token;
|
||||
|
||||
@@ -205,9 +206,38 @@ public class MySqlLexer extends Lexer {
|
||||
}
|
||||
|
||||
protected final void scanString() {
|
||||
{
|
||||
boolean hasSpecial = false;
|
||||
int startIndex = pos + 1;
|
||||
int endIndex = indexOf('\'', startIndex);
|
||||
if (endIndex == -1) {
|
||||
throw new ParserException("unclosed str");
|
||||
}
|
||||
|
||||
String stringVal = subString(startIndex, endIndex - startIndex);
|
||||
for (int i = 0; i < stringVal.length(); ++i) {
|
||||
char ch = stringVal.charAt(i);
|
||||
if (ch == '\\') {
|
||||
hasSpecial = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!hasSpecial) {
|
||||
this.stringVal = stringVal;
|
||||
int pos = endIndex + 1;
|
||||
char ch = charAt(pos);
|
||||
if (ch != '\'') {
|
||||
this.pos = pos;
|
||||
this.ch = ch;
|
||||
token = LITERAL_CHARS;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mark = pos;
|
||||
boolean hasSpecial = false;
|
||||
|
||||
for (;;) {
|
||||
if (isEOF()) {
|
||||
lexError("unclosed.str.lit");
|
||||
@@ -286,6 +316,7 @@ public class MySqlLexer extends Lexer {
|
||||
}
|
||||
|
||||
if (!hasSpecial) {
|
||||
stringVal = "";
|
||||
stringVal = subString(mark + 1, bufPos);
|
||||
} else {
|
||||
stringVal = new String(buf, 0, bufPos);
|
||||
|
||||
@@ -41,7 +41,7 @@ import java.util.Arrays;
|
||||
*/
|
||||
public class Lexer {
|
||||
|
||||
private final String text;
|
||||
protected final String text;
|
||||
protected int pos;
|
||||
protected int mark;
|
||||
|
||||
@@ -78,6 +78,10 @@ public class Lexer {
|
||||
|
||||
return text.charAt(index);
|
||||
}
|
||||
|
||||
public final int indexOf(char ch, int fromIndex) {
|
||||
return text.indexOf(ch, fromIndex);
|
||||
}
|
||||
|
||||
public String addSymbol() {
|
||||
return subString(mark, bufPos);
|
||||
|
||||
Reference in New Issue
Block a user