Here's a somewhat more efficient splicer that is almost as fast as the shifter function:
This is faster than splicer() because it doesn't have the overhead of assigning the chunks to a temporary array.sub s2 { my @r2; while (@_) { push @r2, [ splice @_, 0, 2 ]; } return \@r2; }
By removing the overhead of entering a block on each iteration, it'll be even faster:
As fast as the unaltered shifter() to be precise (but of course shifter() would still win if it were altered in the same way).sub s2 { my @r2; push @r2, [ splice @_, 0, 2 ] while @_; return \@r2; }
- Yes, I reinvent wheels.
- Spam: Visit eurotraQ.
In reply to Re: Processing arrays 2 elements at a time (TIMTOWTDI)
by Juerd
in thread Processing arrays 2 elements at a time (TIMTOWTDI)
by grinder
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |