Skip to content

Instantly share code, notes, and snippets.

@samcv
Created Feb 1, 2017
Embed
What would you like to do?
use nqp;
#proto sub infix:<unicmp>(Str \a, Str \b) is pure { * }
my %decomp_spec;
my $decmpspec = "ABC 04D ABC 04D";
my @list;
my @dec = "ABC", "04D", "ABC", "04D";
# 1.5s
sub slow {
for ^10000 -> $cp {
my @array;
push %decomp_spec{$cp}<mapping>, nqp::atpos(nqp::radix(16, $_, 0, 0), 0) for @dec;
}
}
sub fast {
# 0.5s
for ^10000 -> $cp {
my @array;
for @dec { @array.push(nqp::atpos(nqp::radix(16, $_, 0, 0), 0)) }
%decomp_spec{$cp}<mapping> = @array;
}
}
sub newer {
for ^10000 -> $cp {
%decomp_spec{$cp}<mapping> = @dec.map( { nqp::atpos(nqp::radix(16, $_, 0, 0), 0) } );
}
}
sub hex (\code-str) {
nqp::atpos(nqp::radix(16, code-str, 0, 0), 0)
}
sub oldnew {
for ^10000 -> $cp {
if $decmpspec {
my $dec := nqp::split(' ', $decmpspec);
if nqp::eqat(nqp::atpos($dec, 0), '<', 0) {
%decomp_spec{$cp}<type> = nqp::shift($dec);
}
else {
%decomp_spec{$cp}<type> = 'Canonical';
}
my $array := nqp::list;
for ^nqp::elems($dec) {
nqp::push($array,
nqp::atpos(
nqp::radix(16, nqp::atpos($dec, $_), 0, 0),
0
)
);
}
%decomp_spec{$cp}<mapping> = $array;
}
}
}
sub newnew {
for ^10000 -> $cp {
if $decmpspec {
my @dec = nqp::split(' ', $decmpspec);
if nqp::eqat(nqp::atpos(@dec, 0), '<', 0) {
%decomp_spec{$cp}<type> = nqp::shift(@dec);
}
else {
%decomp_spec{$cp}<type> = 'Canonical';
}
%decomp_spec{$cp}<mapping> = @dec.map( { hex $_ } )
#%decomp_spec{$cp}<mapping> = $array;
}
}
}
oldnew;
say now - INIT now;
say %decomp_spec;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment