Skip to content

Commit

Permalink
Abstract single elem path of [] into R:I
Browse files Browse the repository at this point in the history
This allows the more common path of having multiple values in a
[] to be inlined, causing a small but noticeable improvement.
  • Loading branch information
lizmat committed Jun 16, 2021
1 parent 168da39 commit db074a8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 27 deletions.
17 changes: 17 additions & 0 deletions src/core.c/Rakudo/Internals.pm6
Expand Up @@ -39,6 +39,23 @@ my class Rakudo::Internals {
))
}

method Array-with-one-elem(Mu \type, Mu \value) {
my \array := (nqp::eqaddr(type,Mu) ?? Array !! Array[type]).new;
nqp::p6bindattrinvres(array,List,'$!reified',
nqp::stmts(
nqp::bindpos(
(my \reified := nqp::create(IterationBuffer)),
0,
nqp::p6scalarwithvalue(
nqp::getattr(array,Array,'$!descriptor'),
nqp::decont(value)
)
),
reified
)
)
}

# for use in nqp::splice
my $empty := nqp::list;

Expand Down
30 changes: 3 additions & 27 deletions src/core.c/array_operators.pm6
Expand Up @@ -3,22 +3,11 @@ proto sub circumfix:<[ ]>(Mu $?, *%) {*}
multi sub circumfix:<[ ]>() {
nqp::create(Array)
}

multi sub circumfix:<[ ]>(Iterable:D \iterable) {
nqp::if(
nqp::iscont(iterable),
nqp::p6bindattrinvres(
nqp::create(Array),List,'$!reified',
nqp::stmts(
(my \scalar := nqp::create(Scalar)),
nqp::bindattr(
scalar, Scalar, '$!descriptor',
BEGIN nqp::getcurhllsym('default_cont_spec')
),
nqp::bindattr(scalar,Scalar,'$!value',nqp::decont(iterable)),
nqp::bindpos((my \reified := nqp::create(IterationBuffer)),0,scalar),
reified
)
),
Rakudo::Internals.Array-with-one-elem(Mu, iterable),
nqp::if(
nqp::istype(iterable,List) && nqp::isfalse(iterable.is-lazy),
Array.from-list(iterable),
Expand All @@ -27,20 +16,7 @@ multi sub circumfix:<[ ]>(Iterable:D \iterable) {
)
}
multi sub circumfix:<[ ]>(Mu \x) { # really only for [$foo]
nqp::p6bindattrinvres(
nqp::create(Array),List,'$!reified',
nqp::stmts(
nqp::bindpos(
(my \reified := nqp::create(IterationBuffer)),
0,
nqp::p6scalarwithvalue(
(BEGIN nqp::getcurhllsym('default_cont_spec')),
nqp::decont(x)
)
),
reified
)
)
Rakudo::Internals.Array-with-one-elem(Mu, x)
}

proto sub pop($, *%) {*}
Expand Down

0 comments on commit db074a8

Please sign in to comment.