texinfo-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

branch master updated: Use foreach loop for Info output


From: Gavin D. Smith
Subject: branch master updated: Use foreach loop for Info output
Date: Thu, 18 Jan 2024 16:25:27 -0500

This is an automated email from the git hooks/post-receive script.

gavin pushed a commit to branch master
in repository texinfo.

The following commit(s) were added to refs/heads/master by this push:
     new be96e0d57e Use foreach loop for Info output
be96e0d57e is described below

commit be96e0d57e09e4456ea60f4044a75caa2fce27ac
Author: Gavin Smith <gavinsmith0123@gmail.com>
AuthorDate: Thu Jan 18 21:25:18 2024 +0000

    Use foreach loop for Info output
    
    * tp/Texinfo/Convert/Info.pm (output): Move block of code
    dealing with split output from the end to the beginning of
    a loop, but do not execute it the first time around by checking
    a variable.  This allows changing the loop to a simple foreach
    loop rather than popping from an array each time round.
---
 ChangeLog                  | 10 ++++++++
 tp/Texinfo/Convert/Info.pm | 61 +++++++++++++++++++++++-----------------------
 2 files changed, 41 insertions(+), 30 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 3a4566cbc6..9ae673b2ee 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2024-01-18  Gavin Smith <gavinsmith0123@gmail.com>
+
+       Use foreach loop for Info output
+
+       * tp/Texinfo/Convert/Info.pm (output): Move block of code
+       dealing with split output from the end to the beginning of
+       a loop, but do not execute it the first time around by checking
+       a variable.  This allows changing the loop to a simple foreach
+       loop rather than popping from an array each time round.
+
 2024-01-18  Gavin Smith <gavinsmith0123@gmail.com>
 
        Change handling of blank lines between Info nodes
diff --git a/tp/Texinfo/Convert/Info.pm b/tp/Texinfo/Convert/Info.pm
index 6249a67617..99967d5f11 100644
--- a/tp/Texinfo/Convert/Info.pm
+++ b/tp/Texinfo/Convert/Info.pm
@@ -152,43 +152,19 @@ sub output($$)
     $out_file_nr = 1;
     my $first_node_seen = 0;
     $self->{'count_context'}->[-1]->{'bytes'} += $header_bytes;
-    # FIXME use a simple foreach
-    my @nodes_root_elements = @$tree_units;
-    while (@nodes_root_elements) {
-      my $node_root_element = shift @nodes_root_elements;
-      my $node_text = $self->convert_output_unit($node_root_element);
-      if ($node_text !~ /\n\n$/) {
-        $node_text .= "\n";
-        $self->{'count_context'}->[-1]->{'bytes'}++;
-      }
-      if (!$first_node_seen) {
-        # We are outputting the first node.
-        $first_node_seen = 1;
-        $node_text = $header . $node_text;
-
-        # When the first node was converted in convert_output_unit above, the
-        # text before the first node (type 'before_node_section') was saved in
-        # 'text_before_first_node'.  Save this text for subsequent use in
-        # case of split Info output.
-        if (defined($self->{'text_before_first_node'})) {
-          $complete_header .= $self->{'text_before_first_node'};
-          $complete_header_bytes += length($self->{'text_before_first_node'});
-        }
-      }
-      if ($fh) {
-        print $fh $node_text;
-      } else {
-        $result .= $node_text;
-      }
-      if (defined($self->get_conf('SPLIT_SIZE'))
+    foreach my $node_root_element (@$tree_units) {
+      if ($first_node_seen
+          and defined($self->get_conf('SPLIT_SIZE'))
           and $self->{'count_context'}->[-1]->{'bytes'} >
                   $out_file_nr * $self->get_conf('SPLIT_SIZE')
-          and @nodes_root_elements and $fh) {
+          and $fh) {
+        # Split the output into an additional output file.
         my $close_error;
         if (!close ($fh)) {
           $close_error = $!;
         }
         if ($out_file_nr == 1) {
+          # Switch to split output.
           $self->_register_closed_info_file($output_file);
           if (defined($close_error)) {
             $self->converter_document_error(
@@ -244,6 +220,31 @@ sub output($$)
                                $self->{'count_context'}->[-1]->{'bytes'}];
         #print STDERR join(' --> ', @{$indirect_files[-1]}) ."\n";
       }
+
+      my $node_text = $self->convert_output_unit($node_root_element);
+      if ($node_text !~ /\n\n$/) {
+        $node_text .= "\n";
+        $self->{'count_context'}->[-1]->{'bytes'}++;
+      }
+      if (!$first_node_seen) {
+        # We are outputting the first node.
+        $first_node_seen = 1;
+        $node_text = $header . $node_text;
+
+        # When the first node was converted in convert_output_unit above, the
+        # text before the first node (type 'before_node_section') was saved in
+        # 'text_before_first_node'.  Save this text for subsequent use in
+        # case of split Info output.
+        if (defined($self->{'text_before_first_node'})) {
+          $complete_header .= $self->{'text_before_first_node'};
+          $complete_header_bytes += length($self->{'text_before_first_node'});
+        }
+      }
+      if ($fh) {
+        print $fh $node_text;
+      } else {
+        $result .= $node_text;
+      }
     }
   }
   my $tag_text = '';



reply via email to

[Prev in Thread] Current Thread [Next in Thread]