]> git.donarmstrong.com Git - perltidy.git/commitdiff
speedup by not writing logfile which will not be saved
authorSteve Hancock <perltidy@users.sourceforge.net>
Tue, 13 Oct 2020 22:16:49 +0000 (15:16 -0700)
committerSteve Hancock <perltidy@users.sourceforge.net>
Tue, 13 Oct 2020 22:16:49 +0000 (15:16 -0700)
lib/Perl/Tidy/Formatter.pm
lib/Perl/Tidy/Logger.pm
local-docs/Release-Checklist.md

index 8717f8384733617741fe6acf4d51ef8cee6c71d8..cbfb304dabd444b03b94624a9f9eb513794dafff 100644 (file)
@@ -369,6 +369,7 @@ BEGIN {
 
         _rseqno_controlling_my_ci_ => $i++,
         _ris_seqno_controlling_ci_ => $i++,
+        _save_logfile_             => $i++,
 
     };
 
@@ -671,6 +672,9 @@ sub new {
 
     $self->[_rspecial_side_comment_type_] = {};
 
+    # This flag will be updated later by a call to get_save_logfile()
+    $self->[_save_logfile_] = defined($logger_object);
+
     bless $self, $class;
 
     # Safety check..this is not a class yet
@@ -4013,6 +4017,13 @@ EOM
         return;
     }
 
+    # Update the 'save_logfile' flag based to include any tokenization errors.
+    # We can save time by skipping logfile calls if it is not going to be saved.
+    my $logger_object = $self->[_logger_object_];
+    if ($logger_object) {
+        $self->[_save_logfile_] = $logger_object->get_save_logfile();
+    }
+
     # Make a pass through the lines, looking at lines of CODE and identifying
     # special processing needs, such format skipping sections marked by
     # special comments
@@ -7004,6 +7015,7 @@ sub process_all_lines {
     my $file_writer_object         = $self->[_file_writer_object_];
     my $logger_object              = $self->[_logger_object_];
     my $vertical_aligner_object    = $self->[_vertical_aligner_object_];
+    my $save_logfile               = $self->[_save_logfile_];
 
     # Note for RT#118553, leave only one newline at the end of a file.
     # Example code to do this is in comments below:
@@ -7103,8 +7115,9 @@ sub process_all_lines {
             }
             else {
 
-                # let logger see all non-blank lines of code
-                if ($logger_object) {
+                # Let logger see all non-blank lines of code. This is a slow operation
+                # so we avoid it if it is not going to be saved.
+                if ( $save_logfile && $logger_object ) {
                     $logger_object->black_box( $line_of_tokens,
                         $vertical_aligner_object->get_output_line_number );
                 }
index 1763e824fa5ce6e008ad2557ac0cec2507334bdc..c13947eda74753c9effcbe57eb745ac088d32afa 100644 (file)
@@ -506,6 +506,24 @@ EOM
     return;
 }
 
+sub get_save_logfile {
+
+    # To be called after tokenizer has finished to make formatting more
+    # efficient.  This is not precisely the same as the check used below
+    # because we don't yet have the syntax check result, but since syntax
+    # checking is off by default it will be the same except in debug runs with
+    # syntax checking activated.  In that case it will tell the formatter to
+    # save the logfile even if it may actually be deleted based on the syntax
+    # check.
+    my $self         = shift;
+    my $saw_code_bug = $self->{_saw_code_bug};
+    my $rOpts        = $self->{_rOpts};
+    return
+         $saw_code_bug == 1
+      || $rOpts->{'logfile'}
+      || $rOpts->{'check-syntax'};
+}
+
 sub finish {
 
     # called after all formatting to summarize errors
index ceeb03b3e958b01ebb84c8dd05487943dbeb749c..6d1e6e0492bfa56d2119d45566a4b3f41ef57e65 100644 (file)
@@ -2,7 +2,10 @@
 
 - review tickets at [rt.cpan.org](https://rt.cpan.org/Public/Dist/Display.html?Name=Perl-Tidy) 
 - review the issues at [github](https://github.com/perltidy/perltidy/issues/)
-- compare the new version with previous version on all files in test area
+- compare formatting with the new version with previous version on all files in test area
+- run a blinker test (activate option -I and look for 'Blinker' in DIAGNOSTICS)
+- run a timing test: compare run time with previous version
+- profile with 'nytprof' and compare with previous version
 - run random testing on final version for a significant time before releasing (several days)
 - run 'author tests' on a much larger body of code than is covered by the .t
   files.