[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
branch master updated: * tp/Texinfo/ParserNonXS.pm (gather_previous_item
From: |
Gavin D. Smith |
Subject: |
branch master updated: * tp/Texinfo/ParserNonXS.pm (gather_previous_item): Use splice operation instead of moving items one by one when creating table_term element. No functional changes intended. |
Date: |
Sat, 26 Nov 2022 06:57:46 -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 6a188ef3ca * tp/Texinfo/ParserNonXS.pm (gather_previous_item): Use
splice operation instead of moving items one by one when creating table_term
element. No functional changes intended.
6a188ef3ca is described below
commit 6a188ef3ca6ae3790cbedd554cdd22e679859fe3
Author: Gavin Smith <gavinsmith0123@gmail.com>
AuthorDate: Sat Nov 26 10:42:40 2022 +0000
* tp/Texinfo/ParserNonXS.pm (gather_previous_item):
Use splice operation instead of moving items one by one when
creating table_term element. No functional changes intended.
---
ChangeLog | 6 ++++++
tp/Texinfo/ParserNonXS.pm | 47 +++++++++++++++++++++++++----------------------
2 files changed, 31 insertions(+), 22 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 4f622459bb..c7672c5f7b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2022-11-26 Gavin Smith <gavinsmith0123@gmail.com>
+
+ * tp/Texinfo/ParserNonXS.pm (gather_previous_item):
+ Use splice operation instead of moving items one by one when
+ creating table_term element. No functional changes intended.
+
2022-11-25 Gavin Smith <gavinsmith0123@gmail.com>
* tp/Texinfo/ParserNonXS.pm (gather_previous_item),
diff --git a/tp/Texinfo/ParserNonXS.pm b/tp/Texinfo/ParserNonXS.pm
index 0995e4a9ee..c5ab57eb44 100644
--- a/tp/Texinfo/ParserNonXS.pm
+++ b/tp/Texinfo/ParserNonXS.pm
@@ -1567,19 +1567,23 @@ sub _gather_previous_item($$;$$)
# remove everything that is not an @item/@itemx or before_item to
# put it in the table_definition/inter_item
my $contents_count = scalar(@{$current->{'contents'}});
- my $item_idx;
+ my $splice_idx;
for (my $i = $contents_count - 1; $i >= 0; $i--) {
if ($current->{'contents'}->[$i]->{'cmdname'}
and ($current->{'contents'}->[$i]->{'cmdname'} eq 'item'
or ($current->{'contents'}->[$i]->{'cmdname'} eq 'itemx'))) {
- $item_idx = $i;
+ $splice_idx = $i + 1;
last;
}
}
- $item_idx = -1 if !defined($item_idx);
+ $splice_idx = 0 if !defined($splice_idx);
+
+ my $splice_idx2;
+ $splice_idx2 = $contents_count;
my $new_contents = [];
- @{$new_contents} = splice @{$current->{'contents'}}, $item_idx + 1;
+ @{$new_contents} = splice @{$current->{'contents'}},
+ $splice_idx, $splice_idx2 - $splice_idx;
my $table_after_terms = {'type' => $type,
'contents' => $new_contents};
for my $child (@{$new_contents}) {
@@ -1594,31 +1598,30 @@ sub _gather_previous_item($$;$$)
my $table_term = {'type' => 'table_term',
'parent' => $table_entry, };
push @{$table_entry->{'contents'}}, $table_term;
+
# put everything starting from the end until reaching the previous
- # table entry or beginning of the table in table term.
+ # table entry or beginning of the table in table_term.
my $contents_count = scalar(@{$current->{'contents'}});
- for (my $i = 0; $i < $contents_count; $i++) {
- if ($current->{'contents'}->[-1]->{'type'}
+ my $splice_idx3;
+ for (my $i = $splice_idx - 1; $i >= 0; $i--) {
+ if ($current->{'contents'}->[$i]->{'type'}
# reached the beginning of the table
- and ($current->{'contents'}->[-1]->{'type'} eq 'before_item'
+ and ($current->{'contents'}->[$i]->{'type'} eq 'before_item'
# reached the previous table entry
- or $current->{'contents'}->[-1]->{'type'} eq 'table_entry')) {
+ or $current->{'contents'}->[$i]->{'type'} eq 'table_entry')) {
+ $splice_idx3 = $i + 1;
last;
- } else {
- my $item_content = pop @{$current->{'contents'}};
- $item_content->{'parent'} = $table_term;
- unshift @{$table_term->{'contents'}}, $item_content;
- # debug
- if (! (($item_content->{'cmdname'}
- and ($item_content->{'cmdname'} eq 'itemx'
- or $item_content->{'cmdname'} eq 'item'))
- or ($item_content->{'type'}
- and $item_content->{'type'} eq 'inter_item'))) {
- $self->_bug_message("wrong element in table term", $source_info,
- $item_content);
- }
}
}
+ $splice_idx3 = 0 if !defined($splice_idx3);
+
+ $new_contents = [];
+ @{$new_contents} = splice @{$current->{'contents'}},
+ $splice_idx3, $splice_idx - $splice_idx3;
+ $table_term->{'contents'} = $new_contents;
+ for my $child (@{$new_contents}) {
+ $child->{'parent'} = $table_term;
+ }
push @{$current->{'contents'}}, $table_entry;
if (scalar(@{$table_after_terms->{'contents'}})) {
push @{$table_entry->{'contents'}}, $table_after_terms;
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- branch master updated: * tp/Texinfo/ParserNonXS.pm (gather_previous_item): Use splice operation instead of moving items one by one when creating table_term element. No functional changes intended.,
Gavin D. Smith <=