Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Further work on optimizing :delete in sink context
  • Loading branch information
lizmat committed Aug 4, 2014
1 parent f8b669c commit f48e207
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
5 changes: 2 additions & 3 deletions src/core/Any.pm
Expand Up @@ -531,8 +531,7 @@ sub SLICE_ONE ( \SELF, $one, $array, *%adv ) is hidden_from_backtrace {
if %a.delete_key('delete') { # :delete:*
my $de = SELF.can( $array ?? 'delete_pos' !! 'delete_key' )[0];
if %a.delete_key('SINK') { # :delete:SINK
$de(SELF,$one);
Nil;
$de(SELF,$one,:SINK);
}
elsif !%a { # :delete
$de(SELF,$one);
Expand Down Expand Up @@ -718,7 +717,7 @@ sub SLICE_MORE ( \SELF, $more, $array, *%adv ) is hidden_from_backtrace {
if %a.delete_key('delete') { # :delete:*
my $de = SELF.can( $array ?? 'delete_pos' !! 'delete_key' )[0];
if %a.delete_key('SINK') { # :delete:SINK
$de(SELF,$_) for $more;
$de(SELF,$_,:SINK) for $more;
Nil;
}
elsif !%a { # :delete
Expand Down
2 changes: 1 addition & 1 deletion src/core/Array.pm
Expand Up @@ -92,7 +92,7 @@ class Array { # declared in BOOTSTRAP
DEPRECATED("the :delete adverb with postcircumfix:<[ ]>");
self.delete_pos(pos);
}
method delete_pos(\pos) {
method delete_pos(\pos, :$SINK) {
fail X::Subscript::FromEnd.new(index => pos, type => self.WHAT) if pos < 0;

my $value := self.at_pos(pos); # needed for reification
Expand Down
14 changes: 14 additions & 0 deletions src/core/Hash.pm
Expand Up @@ -144,6 +144,13 @@ my class Hash { # declared in BOOTSTRAP
);
$val;
}
multi method delete_key(Str:D \key, :$SINK!) {
nqp::deletekey(
nqp::getattr(self, EnumMap, '$!storage'),
nqp::unbox_s(key)
);
Nil;
}
multi method delete_key(\key as Str) {
my Mu $val = self.at_key(key);
nqp::deletekey(
Expand All @@ -152,6 +159,13 @@ my class Hash { # declared in BOOTSTRAP
);
$val;
}
multi method delete_key(\key as Str, :$SINK!) {
nqp::deletekey(
nqp::getattr(self, EnumMap, '$!storage'),
nqp::unbox_s(key)
);
Nil;
}

method push(*@values) {
my $previous;
Expand Down

0 comments on commit f48e207

Please sign in to comment.