Skip to content
Permalink
Browse files

Use a single Braid for matches that don't need one

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 6c2f3c8346dabc4eb33684e1f90dfa8a8fd7a862
Showing with 6 additions and 2 deletions.
  1. +6 −2 src/core/Regex.pm6
@@ -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,
@@ -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

0 comments on commit 6c2f3c8

Please sign in to comment.
You can’t perform that action at this time.