charset: avoid intermediate endpoint variable
authorMischa POSLAWSKY <perl@shiar.org>
Sat, 8 Apr 2017 20:45:55 +0000 (22:45 +0200)
committerMischa POSLAWSKY <perl@shiar.org>
Mon, 24 Apr 2017 23:51:41 +0000 (01:51 +0200)
charset.plp

index 54e3b45761017930cf0b466d7d0c3295d995e7f5..b1167ea8a1a7056646941013be51188927bc9c14 100644 (file)
@@ -126,7 +126,6 @@ sub tabinput {
 
        state $visible = {};  # all present tables
        my %row = (offset => 0, cols => 16);
 
        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) {
        my $params = $input =~ s/[+](.*)\z// ? $1 : undef;
 
        if (not defined $params) {
@@ -238,7 +237,7 @@ sub tabinput {
                ]);
 
                $row{offset} = $+{offset};
                ]);
 
                $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) {
                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{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 ' . (
                        $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;
                }
                else {
+                       $row{endpoint} ||= 255;
                        if ($row{set} eq 'MacHebrew' or $row{set} eq 'MacThai') {
                                # array of possibly multiple characters per code point
                                $row{table} = [
                        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
                                ];
                        }
                        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
 
                        if ($row{set} eq 'cp437' and !$row{offset}) {
                                substr($row{table}, 237, 1) = pack 'U*', 0x3D5; # phi sign