Skip to content

Commit 465f84e

Browse files
committed
Less utf8 encode/decode (just decode immediately)
Better than it was, but there are still ways to improve the code. For example, currently it may throw up on non-UTF8 data, which is less than awesome for git bisect (we do not want to care if it is correct UTF-8 or not, we just want to bisect).
1 parent 73a6a1a commit 465f84e

File tree

4 files changed

+7
-9
lines changed

4 files changed

+7
-9
lines changed

Perl6IRCBotable.pm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ sub get_output {
5252
my $s_start = time();
5353
my $pid = open3(undef, \*RESULT, \*RESULT, @_);
5454
{
55-
local $SIG{ALRM} = sub { kill 9, $pid; $out = encode_utf8("«timed out after $wait seconds, output»: "); };
55+
local $SIG{ALRM} = sub { kill 9, $pid; $out = "«timed out after $wait seconds, output»: " };
5656
alarm $wait;
5757
waitpid($pid, 0);
5858
alarm 0;
@@ -62,7 +62,7 @@ sub get_output {
6262
my $exit_status = $? >> 8;
6363
my $exit_signal = $? & 127;
6464

65-
$out .= do { local $/; <RESULT> } // '';
65+
$out .= decode_utf8(do { local $/; <RESULT> }) // ''; # assume UTF-8, that's the best we can do
6666
chomp $out;
6767

6868
return ($out, $exit_status, $exit_signal, $s_end - $s_start)

benchable.pl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ package Benchable;
2525
use parent 'Perl6IRCBotable';
2626

2727
use Cwd qw(cwd abs_path);
28-
use Encode qw(encode_utf8 decode_utf8);
28+
use Encode qw(encode_utf8);
2929
use File::Temp qw(tempfile tempdir);
3030
use List::Util qw(min max);
3131
use Chart::Gnuplot;

bisectable.pl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
package Bisectable;
2525
use parent 'Perl6IRCBotable';
2626

27-
use Encode qw(decode_utf8);
2827
use File::Temp qw(tempfile tempdir);
2928
use Cwd qw(cwd abs_path);
3029

@@ -101,12 +100,13 @@ sub process_message {
101100

102101
if ($exit_good == $exit_bad and $out_good eq $out_bad) {
103102
$self->tell($message, "On both starting points the exit code is $exit_bad and the output is identical as well");
104-
return 'Output on both points: ' . decode_utf8($out_good); # will be gisted automatically if required
103+
return "Output on both points: $out_good"; # will be gisted automatically if required
105104
}
106105
my $output_file = '';
107106
if ($exit_good == $exit_bad) {
108107
$self->tell($message, "Exit code is $exit_bad on both starting points, bisecting by using the output");
109108
(my $fh, $output_file) = tempfile(UNLINK => 1);
109+
binmode $fh, ':encoding(UTF-8)';
110110
print $fh $out_good;
111111
close $fh;
112112
}
@@ -125,7 +125,7 @@ sub process_message {
125125
if ($init_status != 0) {
126126
chdir($oldDir);
127127
$self->tell($message, 'bisect log: ' . $self->upload({ 'query' => $body,
128-
'result' => decode_utf8($init_output) }));
128+
'result' => $init_output }));
129129
return 'bisect init failure';
130130
}
131131
my ($bisect_output, $bisect_status);
@@ -142,7 +142,7 @@ sub process_message {
142142
}
143143
}
144144
$self->tell($message, 'bisect log: ' . $self->upload({ 'query' => $body,
145-
'result' => decode_utf8("$init_output\n$bisect_output") }));
145+
'result' => "$init_output\n$bisect_output" }));
146146
if ($bisect_status != 0) {
147147
chdir($oldDir);
148148
return "'bisect run' failure";

committable.pl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ package Committable;
2525
use parent 'Perl6IRCBotable';
2626

2727
use Cwd qw(cwd abs_path);
28-
use Encode qw(decode_utf8);
2928
use IPC::Signal 'sig_name';
3029

3130
use constant LIMIT => 300;
@@ -88,7 +87,6 @@ sub process_message {
8887
$out = 'No build for this commit';
8988
} else { # actually run the code
9089
($out, my $exit, my $signal, my $time) = $self->get_output($self->BUILDS . "/$full_commit/bin/perl6", $filename);
91-
$out = decode_utf8($out);
9290
$out .= " «exit code = $exit»" if ($exit != 0);
9391
if ($signal != 0) {
9492
my $signal_name = sig_name $signal;

0 commit comments

Comments
 (0)