-
-
Save ugexe/baa168a641894a0731595c812724f76d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# always fails first time after `rm -rf lib/.precomp` with a segfault | |
# but always passes all subsequent runs | |
# removed --> Seq and return an array | |
multi sub decode-base64(Str $str, :$pad, :@alpha, |c) { | |
my $encodings = chars64with(@alpha); | |
my @values = $str.comb(/@$encodings/).rotor(4, :partial).map: -> $chunk { | |
state %lookup = $encodings.kv.hash.antipairs; | |
my $n = [+] $chunk.map: { (%lookup{$_} || 0) +< ((state $m = 24) -= 6) } | |
my $res = (16, 8, 0).map: { $n +> $_ +& 255 } | |
#slip($res.grep(* > 0)); | |
slip($res.head( 3 - ( 4 - $chunk.elems ) ) ); | |
} | |
return @values; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# gives correct results, but segfaults randomly (also Internal error: invalid thread ID 65 in GC work pass) | |
multi sub decode-base64(Str $str, :$pad, :@alpha, |c --> Seq) { | |
my $encodings = chars64with(@alpha); | |
my @result = $str.comb(/@$encodings/).rotor(4, :partial).map: -> $chunk { | |
state %lookup = $encodings.kv.hash.antipairs; | |
my $n = [+] $chunk.map: { (%lookup{$_} || 0) +< ((state $m = 24) -= 6) } | |
my $res = (16, 8, 0).map: { $n +> $_ +& 255 } | |
#slip($res.grep(* > 0)); | |
slip($res.head( 3 - ( 4 - $chunk.elems ) ) ); | |
} | |
@result.Seq; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# always fails, losing items at index 1 and 2 | |
multi sub decode-base64(Str $str, :$pad, :@alpha, |c --> Seq) { | |
my $encodings = chars64with(@alpha); | |
$str.comb(/@$encodings/).rotor(4, :partial).map: -> $chunk { | |
state %lookup = $encodings.kv.hash.antipairs; | |
my $n = [+] $chunk.map: { (%lookup{$_} || 0) +< ((state $m = 24) -= 6) } | |
my $res = (16, 8, 0).map: { $n +> $_ +& 255 } | |
#slip($res.grep(* > 0)); | |
slip($res.head( 3 - ( 4 - $chunk.elems ) ) ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment