Skip to content

Commit

Permalink
Eager implementation of Array.splice.
Browse files Browse the repository at this point in the history
  • Loading branch information
colomon committed Feb 17, 2010
1 parent 215a019 commit 4c3dd04
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/core/Array.pm
Expand Up @@ -28,6 +28,15 @@ augment class Array {
self!fill(1) ?? pir::shift(@!items)
!! fail('Undefined value shifted from empty array');
}

our multi method splice($offset = 0, $size? is copy, *@values) is export {
self!fill;
$size //= self.elems - $offset;
my @ret = self[$offset..^($offset+$size)];
pir::splice__0PPii(@!items, [@values].iterator.eager,
$offset, $size);
@ret;
}
}

our proto sub pop(@array) { @array.pop; }
Expand Down

0 comments on commit 4c3dd04

Please sign in to comment.