-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256
Hello,
I'm developing a perl yenc encoder but unfortunatelly it's not having
the performance i was expecting to have (and it's CPU heavy).
Can i get some help improving it's performance?
This is the code i have (41 lines).
Initially i though about memoize it, but unfortunately i don't think
it's possible.
Replacing the for loop with a map, would be a good option? Does anybody
has any idea to improve it's performance?
Regards,
David Santiago
CODE: The following function receives a binary string.
####
my @YENC_CHAR_MAP = map{($_+42)%256;} (0..0xffff);
my $YENC_NNTP_LINESIZE=128;
sub _yenc_encode{
my ($string) = @_;
my $column = 0;
my $content = '';
my @hexString = unpack('W*',$string); #Converts binary string to hex
for my $hexChar (@hexString) {
my $char= $YENC_CHAR_MAP[$hexChar];
#null || LF || CR || =
if ($char == 0 || $char == 10 || $char == 13 || $char == 61 ||
# TAB || SPC
(($char == 9 || $char == 32) && ($column == $YENC_NNTP_LINESIZE
|| $column==0)) ||
($char==46 && $column==0) # .
) {
$content =$content. '=';
$column+=1;
$char=($char + 64);#%256;
}
$content = $content.chr $char;
$column+=1;
if ($column>= $YENC_NNTP_LINESIZE ) {
$column=0;
$content = $content."\r\n";
}
}
return $content;
}
####
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2
iQEcBAEBCAAGBQJVuoW/AAoJEJ/OLjwuDYzKvMcH/2Q2B1p3L+Q/iPvjfeTNoQfX
V+MsLkSelzjl/rKKRnYgYerHacaTpWxy6sKKnSlTQy2c2XXIXOLLxKZxHjw869bA
hwnlKrl2UnABekJF270J7wIk0K6+zw1BTjHjcPlibfBPTCX6lOoaO0PHy5cHycXC
XQ3+Pjo3e7Ux7dx16vFJq/XJl70LmV5CFShvQoLRtSV3fxvOEE25uGzRm6zCEVSd
cEISGgLXBHwzvpU5+ma4SIuXDcYWDpfNOUukPF7zLHtn+WEjr/CImcM75MvnjUtg
CZn9SIwgOeeNZ22T5SbOitX5uhqyFGOln8Y8DOcHjTCKTD1uem//IclcqZUrXBU=
=r+/T
-----END PGP SIGNATURE-----