On Thu, Oct 17, 2024 at 07:24:26PM +0100, Gavin Smith wrote:
> On Wed, Oct 16, 2024 at 12:50:01AM +0200, Patrice Dumas wrote:
> > On Tue, Oct 15, 2024 at 12:31:07PM +0100, Gavin Smith wrote:
> > > On Mon, Oct 14, 2024 at 11:16:58PM +0200, Patrice Dumas wrote:
> > > > This looks good to me, it is quite simple.  Maybe the number of buckets
> > > > could be set based on the number of sections + nodes + index entries?
> > > 
> > > Great idea, I was concerned that I'd hardcoded the number of buckets.
> > 
> > Could add the number of footnotes * 2 and the number of special units
> > (including special units not associated to a section/node).  And
> > sections number should be * 3 for contents and shortcontents targets.
> > 
> > Also maybe the buckets memory should be allocated to that same number,
> > (number of sections * 3 + number of headings + number of (nodes,
> > anchors, floats) + number of index entries + number of footnotes * 2
> > + number of special units) as we know in advance there there will be
> > this number of registered ids.
> 
> I've started the code for this, but as I am not familiar with the
> XS conversion code at all, it would take me some time to work out
> how to get all of this information.  I tried copying code from
> elsewhere to access self->document in html_converter_customize in
> html_prepare_converter.c, but this wasn't set yet.

Here is a proposal.  I think that the hash maps initializations should
better be done in html_prepare_conversion_units_targets, they should not
be used before.

-- 
Pat
diff --git a/tp/Texinfo/XS/convert/html_prepare_converter.c b/tp/Texinfo/XS/convert/html_prepare_converter.c
index 3d786e1c1f..43743c9ef2 100644
--- a/tp/Texinfo/XS/convert/html_prepare_converter.c
+++ b/tp/Texinfo/XS/convert/html_prepare_converter.c
@@ -4531,6 +4531,46 @@ sort_cmd_targets (CONVERTER *self)
     }
 }
 
+/* return the approximate number of targets for that manual */
+static size_t
+ids_hashmap_predicted_values (CONVERTER *self)
+{
+  size_t sectioning_commands_nr = 0;
+  size_t index_entries_nr = 0;
+  size_t heading_commands_nr = 0;
+  size_t i;
+
+  OUTPUT_UNIT_LIST *special_units = retrieve_output_units
+    (self->document, self->output_units_descriptors[OUDT_special_units]);
+  OUTPUT_UNIT_LIST *associated_special_units = retrieve_output_units
+   (self->document,
+    self->output_units_descriptors[OUDT_associated_special_units]);
+
+  if (self->document->sections_list)
+    sectioning_commands_nr = self->document->sections_list->number;
+
+  if (self->document->indices_info.number > 0)
+    {
+      size_t i;
+      for (i = 0; i < self->sorted_index_names.number; i++)
+        index_entries_nr += self->sorted_index_names.list[i]->entries_number;
+    }
+
+  for (i = 0; heading_commands_list[i]; i++)
+    {
+      enum command_id cmd = heading_commands_list[i];
+      const ELEMENT_LIST *global_command
+        = get_cmd_global_multi_command (&self->document->global_commands, cmd);
+      heading_commands_nr += global_command->number;
+    }
+
+  return special_units->number + associated_special_units->number
+   + self->document->identifiers_target.number
+   + 3 * sectioning_commands_nr
+   + index_entries_nr
+   + self->document->global_commands.footnotes.number * 2;
+}
+
 /* indirectly calls all the functions calling customization function
    requiring elements and output units except for external nodes formatting */
 /* for conversion units except for associated special units that require
@@ -4539,6 +4579,11 @@ void
 html_prepare_conversion_units_targets (CONVERTER *self,
                                        const char *document_name)
 {
+
+  /* initialize IDT hashes here
+  size_t predicted_values = ids_hashmap_predicted_values (self);
+   */
+
   /*
    Do that before the other elements, to be sure that special page ids
    are registered before elements id are.

Reply via email to