From: Mischa POSLAWSKY Date: Sat, 8 Apr 2017 20:45:55 +0000 (+0200) Subject: charset: avoid intermediate endpoint variable X-Git-Tag: v1.10~202 X-Git-Url: http://git.shiar.nl/sheet.git/commitdiff_plain/2dbf5ea33ec8ea148e1859f90d1ced4abef05045 charset: avoid intermediate endpoint variable --- diff --git a/charset.plp b/charset.plp index 54e3b45..b1167ea 100644 --- a/charset.plp +++ b/charset.plp @@ -126,7 +126,6 @@ sub tabinput { state $visible = {}; # all present tables my %row = (offset => 0, cols => 16); - my $endpoint = 255; my $params = $input =~ s/[+](.*)\z// ? $1 : undef; if (not defined $params) { @@ -238,7 +237,7 @@ sub tabinput { ]); $row{offset} = $+{offset}; - $endpoint = $+{endpoint} if $+{endpoint}; + $row{endpoint} = $+{endpoint} if $+{endpoint}; if (my $restart = $+{restart}) { my $skip = int(($+{stop} || $row{offset}) / $row{cols}); for ($skip + 1 .. ($restart / $row{cols}) - 1) { @@ -267,7 +266,8 @@ sub tabinput { $row{cell} = do 'charset-unicode.inc.pl' or Alert('Table data could not be read', $@ || $!); - $row{endpoint } = $row{cell}->{colsize} * ($endpoint || 8191); + $row{endpoint} ||= 8191; + $row{endpoint} *= $row{cell}->{colsize}; $row{startpoint} = $row{cell}->{colsize} * $row{offset}; $row{offset} = 0; $row{set} = 'Unicode ' . ( @@ -283,18 +283,19 @@ sub tabinput { $row{endpoint} = 255; } else { + $row{endpoint} ||= 255; if ($row{set} eq 'MacHebrew' or $row{set} eq 'MacThai') { # array of possibly multiple characters per code point $row{table} = [ - map { Encode::decode($row{set}, pack 'C*', $_) } $row{offset} .. $endpoint + map { Encode::decode($row{set}, pack 'C*', $_) } $row{offset} .. $row{endpoint} ]; } else { # ~16x faster than decoding in loop; # substr strings is twice as fast as splitting to an array - $row{table} = Encode::decode($row{set}, pack 'C*', $row{offset} .. $endpoint); + $row{table} = Encode::decode($row{set}, pack 'C*', $row{offset} .. $row{endpoint}); } - $row{endpoint} = $endpoint - $row{offset}; + $row{endpoint} -= $row{offset}; if ($row{set} eq 'cp437' and !$row{offset}) { substr($row{table}, 237, 1) = pack 'U*', 0x3D5; # phi sign