Skip to content

Commit

Permalink
reduce offsetAndType reads (~33%)
Browse files Browse the repository at this point in the history
  • Loading branch information
lahmatiy committed Sep 23, 2016
1 parent e1dbca5 commit 98c546d
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions lib/parser/scanner.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ function tokenLayout(scanner, source, startPos) {

// rewrite prevType token
tokenCount--;
prevType = offsetAndType[tokenCount] >> 24;
start--;
} else {
type = code;
Expand All @@ -213,14 +214,14 @@ function tokenLayout(scanner, source, startPos) {
}

// console.log(type, scanner.source.substring(start, end));
offsetAndType[tokenCount] = (type << 24) | start;
offsetAndType[tokenCount] = (prevType << 24) | start;

tokenCount++;
start = end;
prevType = type;
}

offsetAndType[tokenCount] = end;
offsetAndType[tokenCount] = (prevType << 24) | end;

scanner.offsetAndType = offsetAndType;
scanner.tokenCount = tokenCount;
Expand Down Expand Up @@ -255,7 +256,7 @@ Scanner.prototype = {
offset += this.currentToken;

if (offset < this.tokenCount) {
return this.offsetAndType[offset] >> 24;
return this.offsetAndType[offset + 1] >> 24;
}

return 0;
Expand Down Expand Up @@ -292,9 +293,10 @@ Scanner.prototype = {

if (next < this.tokenCount) {
this.currentToken = next;
this.tokenType = this.offsetAndType[next] >> 24;
this.tokenStart = this.offsetAndType[next] & OFFSET_MASK;
this.tokenEnd = this.offsetAndType[next + 1] & OFFSET_MASK;
next = this.offsetAndType[next + 1];
this.tokenType = next >> 24;
this.tokenEnd = next & OFFSET_MASK;
} else {
this.currentToken = this.tokenCount;
this.eof = true;
Expand All @@ -307,9 +309,10 @@ Scanner.prototype = {

if (next < this.tokenCount) {
this.currentToken = next;
this.tokenType = this.offsetAndType[next] >> 24;
this.tokenStart = this.tokenEnd;
this.tokenEnd = this.offsetAndType[next + 1] & OFFSET_MASK;
next = this.offsetAndType[next + 1];
this.tokenType = next >> 24;
this.tokenEnd = next & OFFSET_MASK;
} else {
this.currentToken = this.tokenCount;
this.eof = true;
Expand Down

0 comments on commit 98c546d

Please sign in to comment.