Мелкие исправления для повышения скорости

This commit is contained in:
Victor 2016-07-01 18:57:12 +03:00
parent 4df44cadea
commit 03b56ce019
2 changed files with 8 additions and 7 deletions

View File

@ -203,7 +203,7 @@ public final class Lexer {
clearBuffer();
while (true) {
final String text = buffer.toString();
if (!OPERATORS.containsKey(text + current) && !text.isEmpty()) {
if (!text.isEmpty() && !OPERATORS.containsKey(text + current)) {
addToken(OPERATORS.get(text));
return;
}
@ -237,9 +237,9 @@ public final class Lexer {
clearBuffer();
char current = peek(0);
while (true) {
if (current == '`') break;
if (current == '\0') throw error("Reached end of file while parsing extended word.");
if (current == '\n' || current == '\r') throw error("Reached end of line while parsing extended word.");
if (current == '`') break;
buffer.append(current);
current = next();
}
@ -252,7 +252,6 @@ public final class Lexer {
clearBuffer();
char current = peek(0);
while (true) {
if (current == '\0') throw error("Reached end of file while parsing text string.");
if (current == '\\') {
current = next();
switch (current) {
@ -288,6 +287,7 @@ public final class Lexer {
continue;
}
if (current == '"') break;
if (current == '\0') throw error("Reached end of file while parsing text string.");
buffer.append(current);
current = next();
}
@ -306,8 +306,8 @@ public final class Lexer {
private void tokenizeMultilineComment() {
char current = peek(0);
while (true) {
if (current == '\0') throw error("Reached end of file while parsing multiline comment");
if (current == '*' && peek(1) == '/') break;
if (current == '\0') throw error("Reached end of file while parsing multiline comment");
current = next();
}
next(); // *

View File

@ -6,6 +6,7 @@ import com.annimon.ownlang.lib.StringValue;
import com.annimon.ownlang.lib.UserDefinedFunction;
import com.annimon.ownlang.parser.ast.*;
import java.util.ArrayList;
import java.util.EnumMap;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@ -27,9 +28,9 @@ public final class Parser {
private static final Token EOF = new Token(TokenType.EOF, "", -1, -1);
private static final Map<TokenType, BinaryExpression.Operator> assignOperator;
private static final EnumMap<TokenType, BinaryExpression.Operator> assignOperator;
static {
assignOperator = new HashMap<>(BinaryExpression.Operator.values().length + 1);
assignOperator = new EnumMap(TokenType.class);
assignOperator.put(TokenType.EQ, null);
assignOperator.put(TokenType.PLUSEQ, BinaryExpression.Operator.ADD);
assignOperator.put(TokenType.MINUSEQ, BinaryExpression.Operator.SUBTRACT);