Skip to content

Commit

Permalink
Use a single Braid for matches that don't need one
Browse files Browse the repository at this point in the history
Simple regex matches simply don't need a Braid at all, so just make
a single one per time we run Perl 6 and re-use it. It's a percent or
so off a program doing a simple regex match in a hot loop.
  • Loading branch information
jnthn committed Dec 13, 2018
1 parent f18432e commit 6c2f3c8
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/core/Regex.pm6
Expand Up @@ -16,11 +16,15 @@ my class Regex { # declared in BOOTSTRAP
nqp::hllbool(nqp::istype(topic, self))
}

# Create a braid that we can use with all the normal, "boring", regex
# matches that don't have anything exicting on it.
my $braid := Match.'!cursor_init'('').braid;

multi method ACCEPTS(Regex:D \SELF: Any \topic) {
nqp::decont(
nqp::getlexrelcaller(nqp::ctxcallerskipthunks(nqp::ctx()),'$/') =
nqp::stmts(
(my \cursor := SELF.(Match.'!cursor_init'(topic, :c(0)))),
(my \cursor := SELF.(Match.'!cursor_init'(topic, :c(0), :$braid))),
nqp::if(
nqp::isge_i(nqp::getattr_i(cursor,Match,'$!pos'),0),
cursor.MATCH,
Expand Down Expand Up @@ -59,7 +63,7 @@ my class Regex { # declared in BOOTSTRAP
(my $pulled := iter.pull-one),IterationEnd)
|| nqp::isge_i( # valid match?
nqp::getattr_i(
(my \cursor := SELF.(Match.'!cursor_init'($pulled,:0c))),
(my \cursor := SELF.(Match.'!cursor_init'($pulled,:0c,:$braid))),
Match,'$!pos'),
0),
nqp::null
Expand Down

0 comments on commit 6c2f3c8

Please sign in to comment.