Skip to content

Commit

Permalink
Make the shiftpush op a bunch more efficient when handling more than …
Browse files Browse the repository at this point in the history
…a single element. We still call it with 1 far, far too often, but this helps for the other cases. for 1..100000 { } gets 3 times faster with this patch, for example.
  • Loading branch information
jnthn committed Oct 2, 2011
1 parent cbe898f commit 3bc839c
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions src/ops/perl6.ops
Expand Up @@ -1064,21 +1064,18 @@ simply discarded.
inline op perl6_shiftpush(inout PMC, in PMC, in INT) :base_core {
INTVAL count = $3;
INTVAL elems = VTABLE_elements(interp, $2);

if (count > elems) count = elems;

if (!PMC_IS_NULL($1)) {
INTVAL pos = 0;
while (count > 0) {
VTABLE_push_pmc(interp, $1, VTABLE_shift_pmc(interp, $2));
count--;
}
}
else {
while (count > 0) {
VTABLE_shift_pmc(interp, $2);
VTABLE_push_pmc(interp, $1, VTABLE_get_pmc_keyed_int(interp, $2, pos));
count--;
pos++;
}
}
if ($3 > 0)
VTABLE_splice(interp, $2, pmc_new(interp, enum_class_ResizablePMCArray), 0, $3);
}


Expand Down

0 comments on commit 3bc839c

Please sign in to comment.