Skip to content
Permalink
Browse files

Make [@A] and [1,2,3] about 1.4x faster

By using the new nqp::p6 ops for setting up scalars.
  • Loading branch information...
lizmat committed Sep 28, 2018
1 parent 5ff6451 commit e430813fb079ed026703a960668fa9c461edfe8f
Showing with 26 additions and 23 deletions.
  1. +17 −0 src/core/Array.pm6
  2. +9 −23 src/core/array_operators.pm6
@@ -219,6 +219,23 @@ my class Array { # declared in BOOTSTRAP
)
)
}
method from-list(Array:U: Mu \list) {
my \params := nqp::getattr(list,List,'$!reified');
my int $elems = list.elems; # reifies
my int $i = -1;
my \reified := nqp::create(IterationBuffer);
nqp::while(
nqp::islt_i(($i = nqp::add_i($i,1)),$elems),
nqp::bindpos(
reified, $i,
nqp::p6scalarwithvalue(
(BEGIN nqp::getcurhllsym('default_cont_spec')),
nqp::decont(nqp::atpos(params,$i))
)
)
);
nqp::p6bindattrinvres(nqp::create(Array),List,'$!reified',reified)
}

proto method new(|) {*}
multi method new(:$shape!) {
@@ -4,38 +4,24 @@ multi sub circumfix:<[ ]>() {
nqp::create(Array)
}
multi sub circumfix:<[ ]>(Iterable:D \iterable) {
my $reified;
nqp::if(
nqp::iscont(iterable),
nqp::p6bindattrinvres(
nqp::create(Array),List,'$!reified',
nqp::stmts(
nqp::push(
($reified := nqp::create(IterationBuffer)),
nqp::assign(nqp::p6scalarfromdesc(nqp::null),iterable)
(my \scalar := nqp::create(Scalar)),
nqp::bindattr(
scalar, Scalar, '$!descriptor',
BEGIN nqp::getcurhllsym('default_cont_spec')
),
$reified
nqp::bindattr(scalar,Scalar,'$!value',nqp::decont(iterable)),
nqp::bindpos((my \reified := nqp::create(IterationBuffer)),0,scalar),
reified
)
),
nqp::if(
nqp::eqaddr(iterable.WHAT,List),
nqp::if(
iterable.is-lazy,
Array.from-iterator(iterable.iterator),
nqp::stmts( # immutable List
(my int $elems = iterable.elems), # reifies
(my $params := nqp::getattr(iterable,List,'$!reified')),
(my int $i = -1),
($reified := nqp::setelems(nqp::create(IterationBuffer),$elems)),
nqp::while(
nqp::islt_i(($i = nqp::add_i($i,1)),$elems),
nqp::bindpos($reified,$i,nqp::assign(
nqp::p6scalarfromdesc(nqp::null),nqp::atpos($params,$i))
)
),
nqp::p6bindattrinvres(nqp::create(Array),List,'$!reified',$reified)
),
),
nqp::istype(iterable,List) && nqp::isfalse(iterable.is-lazy),
Array.from-list(iterable),
Array.from-iterator(iterable.iterator)
)
)

0 comments on commit e430813

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