Skip to content

Commit

Permalink
Simplify Grammar.parse further
Browse files Browse the repository at this point in the history
- no need to call .MATCH while parsing
- especially if the parse fails
- so only call .MATCH on the final cursor, it will recurse if needed
- this makes parses fail faster, and successful ones marginally faster
  • Loading branch information
lizmat committed Jun 13, 2020
1 parent f10e5bc commit 8be2406
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/core.c/Grammar.pm6
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,17 @@ my class Grammar is Match {
$grammar."$rule"()
)),
nqp::stmts(
(my $match := $cursor.MATCH),
(my int $chars = nqp::chars($orig)),
nqp::while(
$match && nqp::isne_i(
nqp::getattr_i(($match := $cursor.MATCH),Match,'$!pos'),
$chars
),
$match := ($cursor := $cursor.'!cursor_next'()).MATCH
$cursor
&& nqp::isne_i(nqp::getattr_i($cursor,Match,'$!pos'),$chars),
$cursor := $cursor.'!cursor_next'()
),
$match || Nil
nqp::if(
$cursor,
$cursor.MATCH,
Nil
)
),
Nil
))
Expand Down

0 comments on commit 8be2406

Please sign in to comment.