texinfo-commits
[Top][All Lists]
Advanced

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

branch master updated: * tp/Texinfo/Convert/HTML.pm (_unique_target) (_n


From: Patrice Dumas
Subject: branch master updated: * tp/Texinfo/Convert/HTML.pm (_unique_target) (_new_sectioning_command_target, _prepare_index_entries_targets): use a _unique_target function as in C.
Date: Tue, 05 Dec 2023 03:01:58 -0500

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

pertusus pushed a commit to branch master
in repository texinfo.

The following commit(s) were added to refs/heads/master by this push:
     new 649b0b3021 * tp/Texinfo/Convert/HTML.pm (_unique_target) 
(_new_sectioning_command_target, _prepare_index_entries_targets): use a 
_unique_target function as in C.
649b0b3021 is described below

commit 649b0b302144837187b8833bc0099ed4c092e0bb
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Tue Dec 5 09:01:49 2023 +0100

    * tp/Texinfo/Convert/HTML.pm (_unique_target)
    (_new_sectioning_command_target, _prepare_index_entries_targets): use
    a _unique_target function as in C.
---
 ChangeLog                            |  6 ++++
 tp/Texinfo/Convert/HTML.pm           | 56 ++++++++++++++++--------------------
 tp/Texinfo/XS/convert/convert_html.c | 14 ++-------
 3 files changed, 32 insertions(+), 44 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 31c64f424b..2490f6f1f0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2023-12-05  Patrice Dumas  <pertusus@free.fr>
+
+       * tp/Texinfo/Convert/HTML.pm (_unique_target)
+       (_new_sectioning_command_target, _prepare_index_entries_targets): use
+       a _unique_target function as in C.
+
 2023-12-05  Patrice Dumas  <pertusus@free.fr>
 
        * tp/Texinfo/Convert/HTML.pm (_new_sectioning_command_target): align
diff --git a/tp/Texinfo/Convert/HTML.pm b/tp/Texinfo/Convert/HTML.pm
index eb58f3bd01..c0352a26cf 100644
--- a/tp/Texinfo/Convert/HTML.pm
+++ b/tp/Texinfo/Convert/HTML.pm
@@ -9027,6 +9027,22 @@ sub _normalized_label_id_file($$$)
   return ($filename, $target);
 }
 
+sub _unique_target($$)
+{
+  my $self = shift;
+  my $target_base = shift;
+  my $nr=1;
+  my $target = $target_base;
+  while ($self->{'seen_ids'}->{$target}) {
+    $target = $target_base.'-'.$nr;
+    $nr++;
+    # Avoid integer overflow
+    die if ($nr == 0);
+  }
+  return $target;
+}
+
+
 sub _new_sectioning_command_target($$)
 {
   my $self = shift;
@@ -9043,13 +9059,10 @@ sub _new_sectioning_command_target($$)
   }
   my $nr=1;
   my $target = $target_base;
-  if ($target ne '') {
-    while ($self->{'seen_ids'}->{$target}) {
-      $target = $target_base.'-'.$nr;
-      $nr++;
-      # Avoid integer overflow
-      die if ($nr == 0);
-    }
+  if ($target_base ne '') {
+    $target = _unique_target($self, $target_base);
+  } else {
+    $target = '';
   }
 
   # These are undefined if the $target is set to ''.
@@ -9058,25 +9071,11 @@ sub _new_sectioning_command_target($$)
   if ($sectioning_heading_commands{$command->{'cmdname'}}) {
     if ($target ne '') {
       my $target_base_contents = 'toc-'.$normalized_name;
-      $target_contents = $target_base_contents;
-      my $toc_nr = $nr -1;
-      while ($self->{'seen_ids'}->{$target_contents}) {
-        $target_contents = $target_base_contents.'-'.$toc_nr;
-        $toc_nr++;
-        # Avoid integer overflow
-        die if ($toc_nr == 0);
-      }
+      $target_contents = _unique_target($self, $target_base_contents);
 
       my $target_base_shortcontents = 'stoc-'.$normalized_name;
-      $target_shortcontents = $target_base_shortcontents;
-      my $stoc_nr = $nr -1;
-      while ($self->{'seen_ids'}->{$target_shortcontents}) {
-        $target_shortcontents = $target_base_shortcontents
-                                   .'-'.$stoc_nr;
-        $stoc_nr++;
-        # Avoid integer overflow
-        die if ($stoc_nr == 0);
-      }
+      $target_shortcontents
+        = _unique_target($self, $target_base_shortcontents);
     }
   }
 
@@ -10072,14 +10071,7 @@ sub _prepare_index_entries_targets($)
           
Texinfo::Convert::NodeNameNormalization::normalize_transliterate_texinfo(
              $normalize_index_element, $no_unidecode);
         my $target_base = "index-" . $region .$normalized_index;
-        my $nr = 1;
-        my $target = $target_base;
-        while ($self->{'seen_ids'}->{$target}) {
-          $target = $target_base.'-'.$nr;
-          $nr++;
-          # Avoid integer overflow
-          die if ($nr == 0);
-        }
+        my $target = _unique_target($self, $target_base);
         $self->{'seen_ids'}->{$target} = 1;
         my $target_element = $main_entry_element;
         $target_element = $index_entry->{'entry_associated_element'}
diff --git a/tp/Texinfo/XS/convert/convert_html.c 
b/tp/Texinfo/XS/convert/convert_html.c
index 944b8d0c75..d50e55abc1 100644
--- a/tp/Texinfo/XS/convert/convert_html.c
+++ b/tp/Texinfo/XS/convert/convert_html.c
@@ -3784,18 +3784,8 @@ prepare_footnotes_targets (CONVERTER *self)
 
           while (1)
             {
-              int j;
-              int non_unique = 0;
-              for (j = 0; j < self->seen_ids.number; j++)
-                {
-                  if (!strcmp (footid.text, self->seen_ids.list[j])
-                      || !strcmp (docid.text, self->seen_ids.list[j]))
-                    {
-                      non_unique = 1;
-                      break;
-                    }
-                }
-              if (non_unique)
+              if (find_string (&self->seen_ids, footid.text)
+                    || find_string (&self->seen_ids, docid.text))
                 {
                   nr++;
                   if (nr == 0)



reply via email to

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