Skip to content

Commit

Permalink
Stop parsing blocks if not executing (fix #572)
Browse files Browse the repository at this point in the history
Also attempt to speed up block skipping
  • Loading branch information
gfwilliams committed May 25, 2018
1 parent 608192b commit ca13e4d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
1 change: 1 addition & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
Allow for..in to iterate over prototype chains down from Array and Object
Add for(var i of array) to iterate over elements
Added getter and setter support
Stop parsing blocks if not executing (fix #572)

1v99 : Increase jslMatch error buffer size to handle "UNFINISHED TEMPLATE LITERAL" string (#1426)
nRF5x: Make FlashWrite cope with flash writes > 4k
Expand Down
26 changes: 19 additions & 7 deletions src/jsparse.c
Original file line number Diff line number Diff line change
Expand Up @@ -2044,6 +2044,20 @@ NO_INLINE JsVar *jspeExpression() {
return 0;
}

/** Parse a block `{ ... }` */
NO_INLINE void jspeSkipBlock() {
// fast skip of blocks
int brackets = 1;
while (lex->tk && brackets) {
if (lex->tk == '{') brackets++;
else if (lex->tk == '}') {
brackets--;
if (!brackets) return;
}
JSP_ASSERT_MATCH(lex->tk);
}
}

/** Parse a block `{ ... }` but assume brackets are already parsed */
NO_INLINE void jspeBlockNoBrackets() {
if (JSP_SHOULD_EXECUTE) {
Expand All @@ -2064,15 +2078,13 @@ NO_INLINE void jspeBlockNoBrackets() {
}
if (JSP_SHOULDNT_PARSE)
return;
if (!JSP_SHOULD_EXECUTE) {
jspeSkipBlock();
return;
}
}
} else {
// fast skip of blocks
int brackets = 0;
while (lex->tk && (brackets || lex->tk != '}')) {
if (lex->tk == '{') brackets++;
if (lex->tk == '}') brackets--;
JSP_ASSERT_MATCH(lex->tk);
}
jspeSkipBlock();
}
return;
}
Expand Down

0 comments on commit ca13e4d

Please sign in to comment.