Permalink
Browse files

perf(Lexer): operators array -> map

  • Loading branch information...
bigopon authored and jdanyow committed Nov 13, 2017
1 parent d8cfdcc commit 3431ec29996caa6ef2b3bb32861c59073e60009d
Showing with 30 additions and 30 deletions.
  1. +30 −30 src/lexer.js
View
@@ -127,7 +127,7 @@ export class Scanner {
scanOperator(start, text) {
assert(this.peek === text.charCodeAt(0));
assert(OPERATORS.indexOf(text) !== -1);
assert(OPERATORS[text] === 1);
this.advance();
return new Token(start, text).withOp(text);
}
@@ -148,7 +148,7 @@ export class Scanner {
text += two;
}
assert(OPERATORS.indexOf(text) !== -1);
assert(OPERATORS[text] === 1);
return new Token(start, text).withOp(text);
}
@@ -168,7 +168,7 @@ export class Scanner {
// TODO(kasperl): Deal with null, undefined, true, and false in
// a cleaner and faster way.
if (OPERATORS.indexOf(text) !== -1) {
if (OPERATORS[text] === 1) {
result.withOp(text);
} else {
result.withGetterSetter(text);
@@ -292,33 +292,33 @@ export class Scanner {
}
}
const OPERATORS = [
'undefined',
'null',
'true',
'false',
'+',
'-',
'*',
'/',
'%',
'^',
'=',
'==',
'===',
'!=',
'!==',
'<',
'>',
'<=',
'>=',
'&&',
'||',
'&',
'|',
'!',
'?'
];
const OPERATORS = {
'undefined': 1,
'null': 1,
'true': 1,
'false': 1,
'+': 1,
'-': 1,
'*': 1,
'/': 1,
'%': 1,
'^': 1,
'=': 1,
'==': 1,
'===': 1,
'!=': 1,
'!==': 1,
'<': 1,
'>': 1,
'<=': 1,
'>=': 1,
'&&': 1,
'||': 1,
'&': 1,
'|': 1,
'!': 1,
'?': 1
};
const $EOF = 0;
const $TAB = 9;

0 comments on commit 3431ec2

Please sign in to comment.