From 3bc839c00ee03491a7bf8c74923198779a8cc2bb Mon Sep 17 00:00:00 2001 From: jnthn Date: Sun, 2 Oct 2011 02:09:01 +0200 Subject: [PATCH] Make the shiftpush op a bunch more efficient when handling more than 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. --- src/ops/perl6.ops | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/ops/perl6.ops b/src/ops/perl6.ops index 3d2c3ad929a..e917a2bf5b4 100644 --- a/src/ops/perl6.ops +++ b/src/ops/perl6.ops @@ -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); }