Skip to content

Commit

Permalink
Reimplement List.push using nqp::push()
Browse files Browse the repository at this point in the history
The old way was most definitely not thread safe: this way, we have one less
place to look out for thread safety.
  • Loading branch information
lizmat committed Jul 29, 2013
1 parent c810036 commit f8e970b
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 11 deletions.
5 changes: 0 additions & 5 deletions src/core/Array.pm
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,6 @@ class Array {
nqp::findmethod(List, 'REIFY')(self, parcel, nextiter)
}

method STORE_AT_POS(Int \pos, Mu $v is copy) is rw {
nqp::bindpos(nqp::getattr(self, List, '$!items'),
nqp::unbox_i(pos), $v)
}

method STORE(|) {
# get arguments, shift off invocant
my $args := nqp::p6argvmarray();
Expand Down
9 changes: 3 additions & 6 deletions src/core/List.pm
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,10 @@ my class List does Positional {

multi method push(List:D: *@values) {
fail 'Cannot .push an infinite list' if @values.infinite;
my $pos = self.gimme(*);
my $elems = self.gimme(*);
fail 'Cannot .push to an infinite list' if $!nextiter.defined;
self.STORE_AT_POS($pos++, @values.shift) while @values.gimme(1);
nqp::bindattr( self, List, '$!items', nqp::list() ) if $elems == 0;
nqp::push( $!items, @values.shift ) while @values.gimme(1);
self;
}

Expand Down Expand Up @@ -371,10 +372,6 @@ my class List does Positional {
parcel
}

method STORE_AT_POS(Int \pos, Mu \v) is rw {
nqp::bindpos($!items, nqp::unbox_i(pos), v)
}

method FLATTENABLE_LIST() { self.gimme(*); $!items }
method FLATTENABLE_HASH() { nqp::hash() }

Expand Down

0 comments on commit f8e970b

Please sign in to comment.