Skip to content

Commit

Permalink
Speedup some QuantHash internals a bit
Browse files Browse the repository at this point in the history
- pre-size the result_s back to 0
- use push_s to set up the result, so we don't need an index or bindpos_s
  • Loading branch information
lizmat committed May 23, 2020
1 parent b55667e commit 4a728f2
Showing 1 changed file with 9 additions and 18 deletions.
27 changes: 9 additions & 18 deletions src/core.c/Rakudo/QuantHash.pm6
Original file line number Diff line number Diff line change
Expand Up @@ -128,15 +128,11 @@ my class Rakudo::QuantHash {
(my $elems := quanthash.RAW-HASH)
&& (my $iter := nqp::iterator($elems)),
nqp::stmts(
(my $keys := nqp::setelems(nqp::list_s,nqp::elems($elems))),
(my int $i = -1),
(my $keys := # presize result back to 0 so we can push_s
nqp::setelems(nqp::setelems(nqp::list_s,nqp::elems($elems)),0)),
nqp::while(
$iter,
nqp::bindpos_s(
$keys,
($i = nqp::add_i($i,1)),
nqp::iterkey_s(nqp::shift($iter))
)
nqp::push_s($keys,nqp::iterkey_s(nqp::shift($iter)))
),
$keys
),
Expand All @@ -150,15 +146,11 @@ my class Rakudo::QuantHash {
(my $elems := quanthash.RAW-HASH)
&& (my $iter := nqp::iterator($elems)),
nqp::stmts(
(my $values := nqp::setelems(nqp::list_s,nqp::elems($elems))),
(my int $i = -1),
(my $values := # presize result back to 0 so we can push_s
nqp::setelems(nqp::setelems(nqp::list_s,nqp::elems($elems)),0)),
nqp::while(
$iter,
nqp::bindpos_s(
$values,
($i = nqp::add_i($i,1)),
mapper(nqp::iterval(nqp::shift($iter)))
)
nqp::push_s($values,mapper(nqp::iterval(nqp::shift($iter))))
),
$values
),
Expand All @@ -173,15 +165,14 @@ my class Rakudo::QuantHash {
(my $elems := baggy.RAW-HASH)
&& (my $iter := nqp::iterator($elems)),
nqp::stmts(
(my $list := nqp::setelems(nqp::list_s,nqp::elems($elems))),
(my int $i = -1),
(my $list := # presize result back to 0 so we can push_s
nqp::setelems(nqp::setelems(nqp::list_s,nqp::elems($elems)),0)),
nqp::while(
$iter,
nqp::stmts(
nqp::shift($iter),
nqp::bindpos_s(
nqp::push_s(
$list,
($i = nqp::add_i($i,1)),
nqp::concat(
nqp::iterkey_s($iter),
nqp::concat(
Expand Down

0 comments on commit 4a728f2

Please sign in to comment.