Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Properly implement internals [].exists|delete, according to new semi-…

…spec
  • Loading branch information...
commit 6f8668484fe673440e0ddd7cc4a8bbf9050fb182 1 parent c2f7f74
@lizmat lizmat authored
Showing with 16 additions and 18 deletions.
  1. +14 −16 src/core/Array.pm
  2. +2 −2 src/core/List.pm
View
30 src/core/Array.pm
@@ -65,24 +65,22 @@ class Array { # declared in BOOTSTRAP
nqp::bindpos(nqp::getattr(self, List, '$!items'), $pos, bindval)
}
- method delete(@array is rw: *@indices) {
- my $elems = @array.elems;
- my @result;
- for @indices -> $index {
- my $i = $index ~~ Callable
- ?? $index($elems)
- !! +$index;
- @result.push(@array[$i]);
- undefine @array[$i];
+ method delete(\pos) {
+ return Nil if pos < 0;
- # next seems unnecessary but handles an obscure
- # edge case
- if $i == (@array - 1) {
- @array.pop;
- }
+ my $value := self.at_pos(pos);
+ my $items := nqp::getattr(self,List,'$!items');
+
+ if pos == self.end {
+ my $pos = pos;
+ nqp::pop($items);
+ nqp::pop($items)
+ while --$pos >= 0 && nqp::isnull(nqp::atpos($items,$pos));
+ }
+ else {
+ nqp::bindpos($items, pos, nqp::null());
}
- @array.pop while ?@array && !defined @array[@array.elems - 1];
- return @result;
+ $value;
}
method flattens() { 1 }
View
4 src/core/List.pm
@@ -96,9 +96,9 @@ my class List does Positional { # declared in BOOTSTRAP
}
method exists(\pos) {
- return False unless self.DEFINITE;
+ return False if !self.DEFINITE || pos < 0;
self.gimme(pos + 1);
- nqp::p6bool(nqp::existspos($!items, nqp::unbox_i(pos)))
+ nqp::p6bool( !nqp::isnull(nqp::atpos($!items, nqp::unbox_i(pos))) );
}
method gimme($n, :$sink) {
Please sign in to comment.
Something went wrong with that request. Please try again.