Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Reimplement List.push using nqp::push()

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...
commit f8e970b1b9bac654379353337f276ddb2fa47b31 1 parent c810036
@lizmat lizmat authored
Showing with 3 additions and 11 deletions.
  1. +0 −5 src/core/Array.pm
  2. +3 −6 src/core/List.pm
View
5 src/core/Array.pm
@@ -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();
View
9 src/core/List.pm
@@ -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;
}
@@ -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() }
Please sign in to comment.
Something went wrong with that request. Please try again.