Change 33353 by [EMAIL PROTECTED] on 2008/02/22 20:06:15

        Take advantage of the fact that we can use indent as a stdin/stdout
        filter to reduce its workload (and ours) by only sending it the 3 or
        so lines that we are interested in printing, not the preceding
        bucket loads.

Affected files ...

... //depot/perl/Porting/expand-macro.pl#4 edit

Differences ...

==== //depot/perl/Porting/expand-macro.pl#4 (text) ====
Index: perl/Porting/expand-macro.pl
--- perl/Porting/expand-macro.pl#3~33352~       2008-02-22 11:47:52.000000000 
-0800
+++ perl/Porting/expand-macro.pl        2008-02-22 12:06:15.000000000 -0800
@@ -74,14 +74,30 @@
 system "make $tryout" and die;
 
 # if user wants 'indent' formatting ..
-$opt{I} //= '';
-system "indent $opt{I} $tryout" and die if $opt{f};
-system "$opt{F} $opt{I} $tryout" and die if $opt{F};
+my $out_fh;
+
+if ($opt{f} || $opt{F}) {
+    # a: indent is a well behaved filter when given 0 arguments, reading from
+    #    stdin and writing to stdout
+    # b: all our braces should be balanced, indented back to column 0, in the
+    #    headers, hence everything before our #line directive can be ignored
+    #
+    # We can take advantage of this to reduce the work to indent.
+
+    my $indent_command = $opt{f} ? 'indent' : $opt{F};
+
+    if (defined $opt{I}) {
+       $indent_command .= " $opt{I}";
+    }
+    open $out_fh, '|-', $indent_command or die $?;
+} else {
+    $out_fh = \*STDOUT;
+}
 
 open my $fh, '<', $tryout or die "Can't open $tryout: $!";
 
 while (<$fh>) {
-    print if /$sentinel/o .. 1;
+    print $out_fh $_ if /$sentinel/o .. 1;
 }
 
 unless ($opt{k}) {
End of Patch.

Reply via email to