From: Steve Hancock Date: Thu, 13 Jul 2023 22:06:03 +0000 (-0700) Subject: eliminate a call to Perl::Tidy::LineSource for efficiency X-Git-Tag: 20230701.01~4 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=57fcf41048f44cbe8f44b8f4da68f191c3f89863;p=perltidy.git eliminate a call to Perl::Tidy::LineSource for efficiency --- 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;