[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[no subject]
From: |
Patrice Dumas |
Date: |
Fri, 23 Feb 2024 06:35:01 -0500 (EST) |
branch: master
commit 48b242a98bc3f67c4cee512eb6c9f9a35851bd79
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Fri Feb 23 11:50:04 2024 +0100
* /tp/Texinfo/XS/convert/convert_html.c
(prepare_index_entries_targets, html_initialize_output_state),
tp/Texinfo/XS/main/converter_types.h (SORTED_INDEX_NAMES),
tp/Texinfo/XS/main/get_perl_info.c
(find_sorted_index_names_index_entry_extra_index_entry_sv),
tp/Texinfo/XS/main/utils.c (index_number_index_by_name): keep only
indices with entries in sorted_index_names. Have SORTED_INDEX_NAMES
hold a list of INDEX pointers. Remove INDEX_NUMBER.
---
ChangeLog | 11 +++++++++++
tp/Texinfo/XS/convert/convert_html.c | 30 +++++++++++++++++++++---------
tp/Texinfo/XS/main/converter_types.h | 8 ++------
tp/Texinfo/XS/main/get_perl_info.c | 2 +-
tp/Texinfo/XS/main/utils.c | 6 ++++--
5 files changed, 39 insertions(+), 18 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 30553de746..809aefd2e2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2024-02-23 Patrice Dumas <pertusus@free.fr>
+
+ * /tp/Texinfo/XS/convert/convert_html.c
+ (prepare_index_entries_targets, html_initialize_output_state),
+ tp/Texinfo/XS/main/converter_types.h (SORTED_INDEX_NAMES),
+ tp/Texinfo/XS/main/get_perl_info.c
+ (find_sorted_index_names_index_entry_extra_index_entry_sv),
+ tp/Texinfo/XS/main/utils.c (index_number_index_by_name): keep only
+ indices with entries in sorted_index_names. Have SORTED_INDEX_NAMES
+ hold a list of INDEX pointers. Remove INDEX_NUMBER.
+
2024-02-22 Patrice Dumas <pertusus@free.fr>
* tp/Texinfo/XS/main/unicode.c (string_from_utf8): cast to char *
diff --git a/tp/Texinfo/XS/convert/convert_html.c
b/tp/Texinfo/XS/convert/convert_html.c
index 1d4c207ccc..170dd2c5b7 100644
--- a/tp/Texinfo/XS/convert/convert_html.c
+++ b/tp/Texinfo/XS/convert/convert_html.c
@@ -4702,8 +4702,9 @@ prepare_index_entries_targets (CONVERTER *self)
= (int **) malloc (self->sorted_index_names.number * sizeof (int *));
for (i = 0; i < self->sorted_index_names.number; i++)
{
- INDEX *idx = self->sorted_index_names.list[i].index;
+ INDEX *idx = self->sorted_index_names.list[i];
self->shared_conversion_state.formatted_index_entries[i] = 0;
+ /* TODO should always be true */
if (idx->entries_number > 0)
{
self->shared_conversion_state.formatted_index_entries[i]
@@ -12674,7 +12675,7 @@ convert_printindex_command (CONVERTER *self, const enum
command_id cmd,
entry_index_nr
= index_number_index_by_name (&self->sorted_index_names,
index_entry_ref->index_name);
- entry_index = self->sorted_index_names.list[entry_index_nr-1].index;
+ entry_index = self->sorted_index_names.list[entry_index_nr-1];
/* to avoid double error messages, call convert_tree_new_formatting_context
below with a multiple_pass argument if an entry was already formatted once,
@@ -16599,23 +16600,34 @@ html_initialize_output_state (CONVERTER *self, char
*context)
INDEX **index_names = self->document->index_names;
INDEX **sorted_index_names;
size_t index_nr = 0;
+ size_t non_empty_index_nr = 0;
+ size_t idx_non_empty = 0;
for (i = index_names; (idx = *i); i++)
- index_nr++;
-
- self->sorted_index_names.number = index_nr;
+ {
+ index_nr++;
+ if (idx->entries_number > 0)
+ non_empty_index_nr++;
+ }
sorted_index_names = (INDEX **) malloc (index_nr * sizeof (INDEX *));
memcpy (sorted_index_names, index_names, index_nr * sizeof (INDEX *));
qsort (sorted_index_names, index_nr, sizeof (INDEX *),
compare_index_name);
- self->sorted_index_names.list = (INDEX_NUMBER *)
- malloc (index_nr * sizeof (INDEX_NUMBER));
+
+ /* store only non empty indices in sorted_index_names */
+ self->sorted_index_names.number = non_empty_index_nr;
+ self->sorted_index_names.list = (INDEX **)
+ malloc (self->sorted_index_names.number * sizeof (INDEX *));
for (j = 0; j < index_nr; j++)
{
- self->sorted_index_names.list[j].index = sorted_index_names[j];
- self->sorted_index_names.list[j].number = j+1;
+ if (sorted_index_names[j]->entries_number > 0)
+ {
+ self->sorted_index_names.list[idx_non_empty]
+ = sorted_index_names[j];
+ idx_non_empty++;
+ }
}
free (sorted_index_names);
}
diff --git a/tp/Texinfo/XS/main/converter_types.h
b/tp/Texinfo/XS/main/converter_types.h
index 9a5ab48266..3be684d6da 100644
--- a/tp/Texinfo/XS/main/converter_types.h
+++ b/tp/Texinfo/XS/main/converter_types.h
@@ -646,14 +646,10 @@ typedef struct JSLICENSE_CATEGORY_LIST {
JSLICENSE_FILE_INFO_LIST *list;
} JSLICENSE_CATEGORY_LIST;
-typedef struct INDEX_NUMBER {
- size_t number;
- INDEX *index;
-} INDEX_NUMBER;
-
+/* contains only indices with entries */
typedef struct SORTED_INDEX_NAMES {
size_t number;
- INDEX_NUMBER *list;
+ INDEX **list;
} SORTED_INDEX_NAMES;
typedef struct CONVERTER {
diff --git a/tp/Texinfo/XS/main/get_perl_info.c
b/tp/Texinfo/XS/main/get_perl_info.c
index 9c1c126e92..cb0e3873fd 100644
--- a/tp/Texinfo/XS/main/get_perl_info.c
+++ b/tp/Texinfo/XS/main/get_perl_info.c
@@ -1252,7 +1252,7 @@ find_sorted_index_names_index_entry_extra_index_entry_sv (
size_t index_nr
= index_number_index_by_name (sorted_index_names,
index_name);
- return &sorted_index_names->list[index_nr -1].index
+ return &sorted_index_names->list[index_nr -1]
->index_entries[entry_number -1];
}
}
diff --git a/tp/Texinfo/XS/main/utils.c b/tp/Texinfo/XS/main/utils.c
index 456a3d2fb3..687cf75b40 100644
--- a/tp/Texinfo/XS/main/utils.c
+++ b/tp/Texinfo/XS/main/utils.c
@@ -627,7 +627,9 @@ ultimate_index (INDEX *index)
}
/* only used in conversion, on sorted indices names */
-/* TODO also a bsearch? */
+/* A linear search is probably ok, as the number of
+ indices should always be small. If needed a bsearch
+ could also be implemented. */
size_t
index_number_index_by_name (const SORTED_INDEX_NAMES *sorted_indices,
const char *name)
@@ -636,7 +638,7 @@ index_number_index_by_name (const SORTED_INDEX_NAMES
*sorted_indices,
for (i = 0; i < sorted_indices->number; i++)
{
- if (!strcmp (sorted_indices->list[i].index->name, name))
+ if (!strcmp (sorted_indices->list[i]->name, name))
return i+1;
}
return 0;