texinfo-commits
[Top][All Lists]
Advanced

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

[no subject]


From: Gavin D. Smith
Date: Mon, 21 Nov 2022 14:44:17 -0500 (EST)

branch: master
commit 52d75d86b5db4d4394008931ad5ab61cb56a989b
Author: Gavin Smith <gavinsmith0123@gmail.com>
AuthorDate: Mon Nov 21 19:14:40 2022 +0000

    * tp/Texinfo/ParserNonXS.pm (_gather_previous_item):
    Splice end of contents array instead of unshifting items from
    end one at a time.  No functional changes intended.  This should
    make it simpler to work forwards and find index commands
    immediately following @item and/or @itemx.
---
 ChangeLog                 |  8 ++++++++
 tp/Texinfo/ParserNonXS.pm | 25 ++++++++++++++++---------
 2 files changed, 24 insertions(+), 9 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 0ca1b102a8..882e07fdc5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2022-11-21  Gavin Smith  <gavinsmith0123@gmail.com>
+
+       * tp/Texinfo/ParserNonXS.pm (_gather_previous_item):
+       Splice end of contents array instead of unshifting items from
+       end one at a time.  No functional changes intended.  This should
+       make it simpler to work forwards and find index commands
+       immediately following @item and/or @itemx.
+
 2022-11-20  Patrice Dumas  <pertusus@free.fr>
 
        * tp/Texinfo/Convert/HTML.pm (_convert_printindex_command): remove
diff --git a/tp/Texinfo/ParserNonXS.pm b/tp/Texinfo/ParserNonXS.pm
index 67dd29f392..aca1abe497 100644
--- a/tp/Texinfo/ParserNonXS.pm
+++ b/tp/Texinfo/ParserNonXS.pm
@@ -1563,22 +1563,29 @@ sub _gather_previous_item($$;$$)
   } else {
     $type = 'table_item';
   }
-  my $table_after_terms = {'type' => $type,
-                           'contents' => []};
+
   # remove everything that is not an @item/@itemx or before_item to
-  # put it in the table_item/inter_item, starting from the end.
+  # put it in the table_item/inter_item
   my $contents_count = scalar(@{$current->{'contents'}});
-  for (my $i = 0; $i < $contents_count; $i++) {
-    if ($current->{'contents'}->[-1]->{'cmdname'}
+  my $item_idx;
+  for (my $i = $contents_count - 1; $i >= 0; $i--) {
+    if ($current->{'contents'}->[$i]->{'cmdname'}
         and ($current->{'contents'}->[-1]->{'cmdname'} eq 'item'
              or ($current->{'contents'}->[-1]->{'cmdname'} eq 'itemx'))) {
+      $itemx_idx = $i;
       last;
-    } else {
-      my $item_content = pop @{$current->{'contents'}};
-      $item_content->{'parent'} = $table_after_terms;
-      unshift @{$table_after_terms->{'contents'}}, $item_content;
     }
   }
+  $item_idx = -1 if !defined($item_idx);
+
+  my $new_contents = [];
+  @{$new_contents} = splice @{$current->{'contents'}}, $item_idx + 1;
+  my $table_after_terms = {'type' => $type,
+                           'contents' => $new_contents};
+  for my $child (@{$new_contents}) {
+    $child->{'parent'} = $table_after_terms;
+  }
+
   if ($type eq 'table_item') {
     # setup a table_entry
     my $table_entry = {'type' => 'table_entry',



reply via email to

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