Permalink
Browse files

Make prefix ~^ Blob:D about 300x faster

- on a 10K buffer
- more importantly, it now also handles Buf's correctly
  • Loading branch information...
lizmat committed Feb 27, 2016
1 parent 763d430 commit fb74abc314efa2dcc7f4866f1378f40a17410a50
Showing with 13 additions and 4 deletions.
  1. +13 −4 src/core/Buf.pm
@@ -627,10 +627,19 @@ multi sub infix:<~>(Blob:D $a, Blob:D $b) {
nqp::splice($res, $bdc, $alen, $blen);
}

multi sub prefix:<~^>(Blob:D $a) {
$a ~~ Blob[int16] ?? $a.new($a.list.map: 0xFFFF - *) !!
$a ~~ Blob[int32] ?? $a.new($a.list.map: 0xFFFFFFFF - *) !!
$a.new($a.list.map: 0xFF - *);
multi sub prefix:<~^>(Blob:D \a) {
my $a := nqp::decont(a);
my int $elems = nqp::elems($a);

my $r := nqp::create($a);
nqp::setelems($a,$elems);

my int $i = -1;
my int $mask = 0xFFFFFFFFFFFFFFFF;
nqp::bindpos_i($r,$i,nqp::bitxor_i(nqp::atpos_i($a,$i),$mask))
while nqp::islt_i($i = $i + 1,$elems);

$r
}

multi sub infix:<~&>(Blob:D \a, Blob:D \b) {

0 comments on commit fb74abc

Please sign in to comment.