Skip to content
This repository has been archived by the owner on Jan 13, 2022. It is now read-only.

Commit

Permalink
Inline the reduce stage in the stack-based binary expression.
Browse files Browse the repository at this point in the history
Now that we don't need the generalized reduce for the final stack
clean-up, we can just inline the function. No noticeable performance
change is observed.

http://code.google.com/p/esprima/issues/detail?id=352
  • Loading branch information
ariya committed Dec 8, 2012
1 parent 0c5ac68 commit 68bd43e
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions esprima.js
Original file line number Diff line number Diff line change
Expand Up @@ -2073,17 +2073,8 @@ parseStatement: true, parseSourceElement: true */
// 11.10 Binary Bitwise Operators
// 11.11 Binary Logical Operators

// Reduce: make a binary expression from the three topmost entries.
function reduceBinary(stack) {
var right = stack.pop(),
operator = stack.pop().value,
left = stack.pop();

stack.push(delegate.createBinaryExpression(operator, left, right));
}

function parseBinaryExpression() {
var expr, token, prec, previousAllowIn, stack, i;
var expr, token, prec, previousAllowIn, stack, right, operator, left, i;

previousAllowIn = state.allowIn;
state.allowIn = true;
Expand All @@ -2102,9 +2093,12 @@ parseStatement: true, parseSourceElement: true */

while ((prec = binaryPrecedence(lookahead, previousAllowIn)) > 0) {

// Reduce.
// Reduce: make a binary expression from the three topmost entries.
while ((stack.length > 2) && (prec <= stack[stack.length - 2].prec)) {
reduceBinary(stack);
right = stack.pop();
operator = stack.pop().value;
left = stack.pop();
stack.push(delegate.createBinaryExpression(operator, left, right));
}

// Shift.
Expand Down

0 comments on commit 68bd43e

Please sign in to comment.