texinfo-commits
[Top][All Lists]
Advanced

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

[no subject]


From: Patrice Dumas
Date: Sun, 24 Dec 2023 08:17:08 -0500 (EST)

branch: master
commit 4aa029caf18c1797a7cb7c52e03f920b14c62c72
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Sat Dec 23 17:58:40 2023 +0100

    * tp/Texinfo/XS/convert/ConvertXS.xs (html_register_footnote): use
    extra global_command_number to find footnote in C global commands
    data.
---
 ChangeLog                          |  6 ++++++
 tp/Texinfo/XS/convert/ConvertXS.xs | 36 ++++++++++++++++++++++++++++--------
 2 files changed, 34 insertions(+), 8 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index ece5f44825..2a7ae2b7e5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -35,6 +35,12 @@
        the output throughout the conversion in Plaintext.pm in order to
        keep track of byte offsets in a simpler and more reliable way.
 
+2023-12-23  Patrice Dumas  <pertusus@free.fr>
+
+       * tp/Texinfo/XS/convert/ConvertXS.xs (html_register_footnote): use
+       extra global_command_number to find footnote in C global commands
+       data.
+
 2023-12-23  Patrice Dumas  <pertusus@free.fr>
 
        * tp/Texinfo/XS/main/build_perl_info.c (output_unit_to_perl_hash): add
diff --git a/tp/Texinfo/XS/convert/ConvertXS.xs 
b/tp/Texinfo/XS/convert/ConvertXS.xs
index b1096017c7..1cdfba435c 100644
--- a/tp/Texinfo/XS/convert/ConvertXS.xs
+++ b/tp/Texinfo/XS/convert/ConvertXS.xs
@@ -923,19 +923,39 @@ html_register_footnote (SV *converter_in, SV *command, 
footid, docid, int number
                                   "html_register_footnote");
          if (self)
            {
-             /* find footnote in XS.  First use number_in_doc, if not
-                effective, do a linear search */
-             /* TODO if not found, could determine an offset with
-                     number_in_doc and reuse it. */
-             /* TODO another possibility would be to setup a sorted array
-                when setting up the footnotes targets and use bsearch,
-                although it is not clear that it would be more efficient */
+             /* find footnote in XS.  First use index in global commands,
+                then number_in_doc, and if not effective, do a linear search */
              ELEMENT *footnote = 0;
              ELEMENT *current;
              HV *command_hv = (HV *) SvRV (command);
              ELEMENT_LIST *footnotes
                 = &self->document->global_commands->footnotes;
-             if (number_in_doc - 1 < footnotes->number)
+             SV **extra_sv
+                 = hv_fetch (command_hv, "extra", strlen ("extra"), 0);
+             int global_command_number = 0;
+
+             if (extra_sv)
+               {
+                 HV *extra_hv = (HV *) SvRV (*extra_sv);
+                 SV **global_command_number_sv
+                    = hv_fetch (extra_hv, "global_command_number",
+                                strlen ("global_command_number"), 0);
+                 if (global_command_number_sv)
+                   global_command_number = SvIV (*global_command_number_sv);
+               }
+             if (global_command_number > 0
+                 && global_command_number - 1 < footnotes->number)
+               {
+                 ELEMENT *current = footnotes->list[global_command_number - 1];
+                 if (command_hv == current->hv)
+                   footnote = current;
+                 else
+                   fprintf (stderr,
+                         "REMARK: global footnote %d %s not directly found\n",
+                            global_command_number, footid);
+               }
+             /* the next two ways should never be needed */
+             if (!footnote && number_in_doc - 1 < footnotes->number)
                {
                  ELEMENT *current = footnotes->list[number_in_doc - 1];
                  if (command_hv == current->hv)



reply via email to

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