From 57fcf41048f44cbe8f44b8f4da68f191c3f89863 Mon Sep 17 00:00:00 2001 From: Steve Hancock Date: Thu, 13 Jul 2023 15:06:03 -0700 Subject: [PATCH] eliminate a call to Perl::Tidy::LineSource for efficiency --- lib/Perl/Tidy.pm | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/lib/Perl/Tidy.pm b/lib/Perl/Tidy.pm index 696f808f..070fb280 100644 --- a/lib/Perl/Tidy.pm +++ b/lib/Perl/Tidy.pm @@ -1516,17 +1516,25 @@ sub get_decoded_string_buffer { my $rOpts = $self->[_rOpts_]; - my $source_object = Perl::Tidy::LineSource->new( - input_file => $input_file, - rOpts => $rOpts, - ); + my ( $fh, $input_name ) = Perl::Tidy::streamhandle( $input_file, 'r' ); # return nothing if error - return unless ($source_object); + return unless ($fh); - my $buf = EMPTY_STRING; - while ( my $line = $source_object->get_line() ) { + my $buf = EMPTY_STRING; + my $count = 0; + while ( my $line = $fh->getline() ) { $buf .= $line; + $count++; + } + + # patch to read raw mac files under unix, dos + # look for a single line with embedded \r's + if ( $count == 1 && $buf =~ /[\015][^\015\012]/ ) { + my @lines = map { $_ . "\n" } split /\015/, $buf; + if ( @lines > 1 ) { + $buf = join "", @lines; + } } my $encoding_in = EMPTY_STRING; -- 2.39.5