parallel: mbtrunc speedup.

This commit is contained in:
Ole Tange 2023-04-22 21:17:48 +02:00
parent 327e271565
commit 72a55906d3

View file

@ -11430,18 +11430,21 @@ sub print_files($) {
} }
} }
sub truncate_mbs($$) { sub mbtrunc($$) {
# Simple mbtrunc to avoid using Text::WideChar::Util
my $str = shift; my $str = shift;
my $len = shift; my $len = shift;
if(::mbswidth($str) == length($str)) { if(::mbswidth($str) == length($str)) {
$str = substr($str,0,$len); $str = substr($str,0,$len);
} else { } else {
$str=~s/(.{$len}).*/$1/; # mb chars (ヌー平行) are wider than 1 char on screen
my $rlen = (::mbswidth($str) - $len)/2; # We need at most $len chars - they may be wide
$str=~s/.{$rlen}$//; $str =~ s/(.{$len}).*/$1/;
while(::mbswidth($str) > $len) { my $rlen = int((::mbswidth($str) - $len)/2+0.5);
$str=~s/.$//; do {
} $str =~ s/.{$rlen}$//;
$rlen = int((::mbswidth($str) - $len)/2+0.5);
} while($rlen >= 1);
} }
return $str; return $str;
} }
@ -11468,10 +11471,10 @@ sub print_files($) {
::untabify(::decode_utf8($self->{$out_fh,'latestline'})); ::untabify(::decode_utf8($self->{$out_fh,'latestline'}));
# -1 to make space for $truncated_str # -1 to make space for $truncated_str
my $maxtaglen = $termcol - 1; my $maxtaglen = $termcol - 1;
$untabify_tag = truncate_mbs($untabify_tag,$maxtaglen); $untabify_tag = mbtrunc($untabify_tag,$maxtaglen);
my $taglen = ::mbswidth($untabify_tag); my $taglen = ::mbswidth($untabify_tag);
my $maxstrlen = $termcol - $taglen - 1; my $maxstrlen = $termcol - $taglen - 1;
$untabify_str = truncate_mbs($untabify_str,$maxstrlen); $untabify_str = mbtrunc($untabify_str,$maxstrlen);
my $strlen = ::mbswidth($untabify_str); my $strlen = ::mbswidth($untabify_str);
my $truncated_tag = ""; my $truncated_tag = "";
my $truncated_str = ""; my $truncated_str = "";