Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Update shiftpush opcode to be quite a bit faster.
  • Loading branch information
pmichaud committed Jun 23, 2011
1 parent d19672e commit ce956a6
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 18 deletions.
4 changes: 2 additions & 2 deletions src/Perl6/Actions.pm
Expand Up @@ -8,8 +8,8 @@ INIT {
p6box_s => 'perl6_box_str__Ps',
p6bool => 'perl6_booleanize__Pi',
p6isa => 'type_check__IPP',
p6listiter => 'perl6_iter_from_rpa__PP',
p6list => 'perl6_list_from_rpa__PPP',
p6listiter => 'perl6_iter_from_rpa__PPP',
p6list => 'perl6_list_from_rpa__PPPP',

lcm_i => 'lcm__Iii',
gcd_i => 'gcd__Iii',
Expand Down
2 changes: 1 addition & 1 deletion src/core/List.pm
Expand Up @@ -78,7 +78,7 @@ class List {
|| nqp::isnull($!items)
|| nqp::islt_i(nqp::elems($!items), nqp::unbox_i($n));
pir__perl6_box_rpa__PP(
pir::perl6_shiftn__0PPi(nqp::list(), $!items, nqp::unbox_i($n))
pir::perl6_shiftpush__0PPi(nqp::list(), $!items, nqp::unbox_i($n))
)
}

Expand Down
2 changes: 1 addition & 1 deletion src/core/ListIter.pm
Expand Up @@ -21,7 +21,7 @@ my class ListIter {
pir::perl6_rpa_find_type__IPPii(
$!rest, Parcel, 0, nqp::unbox_i($index)))
if $flattens;
pir::perl6_shiftn__0PPi($rpa, $!rest, nqp::unbox_i($index));
pir::perl6_shiftpush__0PPi($rpa, $!rest, nqp::unbox_i($index));
if $!rest && nqp::islt_i(nqp::elems($rpa), nqp::unbox_i($count)) {
$x := nqp::shift($!rest);
if nqp::isconcrete($x) {
Expand Down
24 changes: 10 additions & 14 deletions src/ops/perl6.ops
Expand Up @@ -789,35 +789,31 @@ inline op perl6_rpa_find_type(out INT, in PMC, in PMC, in INT, in INT)

/*

=item perl6_shiftn(inout PMC, in PMC, in INT)
=item perl6_shiftpush(inout PMC, in PMC, in INT)

Shifts up to $3 elements from $2, pushing each shifted onto $1.
$1 can be PMCNULL, in which case the shifted elements are
simply discarded.

*/
inline op perl6_shiftn(inout PMC, in PMC, in INT) :base_core {
inline op perl6_shiftpush(inout PMC, in PMC, in INT) :base_core {
INTVAL count = $3;
INTVAL elems = VTABLE_elements(interp, $2);
INTVAL i;

if (count > elems) count = elems;

/* if we have a destination PMC in $1, then push the first
count elements of $2 onto it */
if (!PMC_IS_NULL($1)) {
for (i = 0; i < count; i++) {
VTABLE_push_pmc(interp, $1,
VTABLE_get_pmc_keyed_int(interp, $2, i));
while (count > 0) {
VTABLE_push_pmc(interp, $1, VTABLE_shift_pmc(interp, $2));
count--;
}
}

/* now shift count elements off of $2 */
for (i = 0; i < elems - count; i++) {
VTABLE_set_pmc_keyed_int(interp, $2, i,
VTABLE_get_pmc_keyed_int(interp, $2, i+count));
else {
while (count > 0) {
VTABLE_shift_pmc(interp, $2);
count--;
}
}
VTABLE_set_integer_native(interp, $2, elems-count);
}


Expand Down

0 comments on commit ce956a6

Please sign in to comment.