From: Steve Hancock Date: Thu, 10 Aug 2023 14:12:52 +0000 (-0700) Subject: do not call Encode::Guess for pure ascii files X-Git-Tag: 20230701.03~22 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=27899b81e87ab94ef7b82b00e396ebe6745b6efc;p=perltidy.git do not call Encode::Guess for pure ascii files This speeds up perltidy by about 2% for most perl scripts. --- diff --git a/CHANGES.md b/CHANGES.md index 47394574..be5a6d98 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -6,8 +6,8 @@ to limit tidy operations to a limited line range. Line numbers start with 1. The man pages have details. - - This version runs about five percent faster than the previous release - on large files. + - This version runs about 7% faster than the previous release on + large files. ## 2023 07 01 diff --git a/lib/Perl/Tidy.pm b/lib/Perl/Tidy.pm index 1bb337b7..79ba7df9 100644 --- a/lib/Perl/Tidy.pm +++ b/lib/Perl/Tidy.pm @@ -1494,8 +1494,11 @@ sub get_decoded_string_buffer { # encodings sometimes works but can sometimes lead to disaster by # using an incorrect decoding. - my $decoder = guess_encoding( ${$rinput_string}, 'utf8' ); - if ( ref($decoder) ) { + my $decoder; + if ( ${$rinput_string} =~ /[^[:ascii:]]/ ) { + $decoder = guess_encoding( ${$rinput_string}, 'utf8' ); + } + if ( $decoder && ref($decoder) ) { $encoding_in = $decoder->name; if ( $encoding_in ne 'UTF-8' && $encoding_in ne 'utf8' ) { $encoding_in = EMPTY_STRING;