Skip to content

Commit

Permalink
Make my int @A = ^5000 about 1.7x as fast
Browse files Browse the repository at this point in the history
By not binding values to specific indices, but just pushing values onto
the native array.
  • Loading branch information
lizmat committed Jul 11, 2018
1 parent 88e913b commit 5682ee1
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/core/native_array.pm6
Original file line number Diff line number Diff line change
Expand Up @@ -1040,12 +1040,11 @@ my class array does Iterable {
nqp::getattr(range,Range,'$!max'),
nqp::getattr_i(range,Range,'$!excludes-max')
)),
nqp::setelems(self, nqp::add_i(nqp::sub_i($max,$val),1)),
(my int $i = -1),
nqp::setelems(self,0), # make sure we start from scratch
($val = nqp::sub_i($val,1)),
nqp::while(
nqp::isle_i(($val = nqp::add_i($val,1)),$max),
nqp::bindpos_i(self,($i = nqp::add_i($i,1)),$val)
nqp::push_i(self,$val)
),
self
),
Expand Down

1 comment on commit 5682ee1

@b2gills
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if the following would pre-allocate the array

nqp::setelems(self, nqp::add_i(nqp::sub_i($max,$val),1)),
nqp::setelems(self, 0),

Please sign in to comment.