]> git.donarmstrong.com Git - perltidy.git/commitdiff
do not call Encode::Guess for pure ascii files
authorSteve Hancock <perltidy@users.sourceforge.net>
Thu, 10 Aug 2023 14:12:52 +0000 (07:12 -0700)
committerSteve Hancock <perltidy@users.sourceforge.net>
Thu, 10 Aug 2023 14:12:52 +0000 (07:12 -0700)
This speeds up perltidy by about 2% for most perl scripts.

CHANGES.md
lib/Perl/Tidy.pm

index 473945746417831f5e4011791c336c8c21ddc33b..be5a6d98119ae03de853dbf17cbdccab5de9d25d 100644 (file)
@@ -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
 
index 1bb337b773d4c658a130c1e4d3f239eb63ea6765..79ba7df95501f4f81ee46ca13347d592a313b629 100644 (file)
@@ -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;