[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
branch master updated: * tp/Texinfo/XS/convert/converter.c (get_converte
From: |
Patrice Dumas |
Subject: |
branch master updated: * tp/Texinfo/XS/convert/converter.c (get_converter_indices_sorted_by_index) (get_converter_indices_sorted_by_letter), tp/Texinfo/XS/main/document.c (sorted_indices_by_index) (sorted_indices_by_letter): have sorted_indices_by_* return the full collation indices information, not only the sorted indices, such that the caller may know the language set in collation structure. In get_converter_indices_sorted_by_*, get the language from sorted_indices_by_* collation indices information and pass i [...] |
Date: |
Mon, 15 Apr 2024 13:34:59 -0400 |
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 c391689c4b * tp/Texinfo/XS/convert/converter.c
(get_converter_indices_sorted_by_index)
(get_converter_indices_sorted_by_letter), tp/Texinfo/XS/main/document.c
(sorted_indices_by_index) (sorted_indices_by_letter): have sorted_indices_by_*
return the full collation indices information, not only the sorted indices,
such that the caller may know the language set in collation structure. In
get_converter_indices_sorted_by_*, get the language from sorted_indices_by_*
collation indices i [...]
c391689c4b is described below
commit c391689c4b37743ae0f641aaad4aaa791f020031
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Mon Apr 15 19:34:51 2024 +0200
* tp/Texinfo/XS/convert/converter.c
(get_converter_indices_sorted_by_index)
(get_converter_indices_sorted_by_letter),
tp/Texinfo/XS/main/document.c (sorted_indices_by_index)
(sorted_indices_by_letter): have sorted_indices_by_* return the
full collation indices information, not only the sorted indices, such
that the caller may know the language set in collation structure.
In get_converter_indices_sorted_by_*, get the language from
sorted_indices_by_* collation indices information and pass it through
an argument pointer reference.
Update callers.
* tp/Texinfo/XS/main/get_perl_info.c
(get_language_document_hv_sorted_indices),
tp/Texinfo/XS/convert/ConvertXS.xs
(get_converter_indices_sorted_by_index)
(get_converter_indices_sorted_by_letter): cache sorted indices built
as Perl data in Perl data, such as to build the perl data only once,
not for every index. The cached data is retrieved with
get_language_document_hv_sorted_indices, which also creates the hash
where the sorted indices are stored, if needed.
---
ChangeLog | 24 ++++++
tp/Texinfo/XS/convert/ConvertXS.xs | 143 ++++++++++++++++++++++-------------
tp/Texinfo/XS/convert/convert_html.c | 3 +-
tp/Texinfo/XS/convert/converter.c | 32 +++++---
tp/Texinfo/XS/convert/converter.h | 5 +-
tp/Texinfo/XS/main/document.c | 8 +-
tp/Texinfo/XS/main/document.h | 6 +-
tp/Texinfo/XS/main/get_perl_info.c | 42 ++++++++++
tp/Texinfo/XS/main/get_perl_info.h | 3 +
9 files changed, 196 insertions(+), 70 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 2a7192ccf3..92a9831c39 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,27 @@
+2024-04-15 Patrice Dumas <pertusus@free.fr>
+
+ * tp/Texinfo/XS/convert/converter.c
+ (get_converter_indices_sorted_by_index)
+ (get_converter_indices_sorted_by_letter),
+ tp/Texinfo/XS/main/document.c (sorted_indices_by_index)
+ (sorted_indices_by_letter): have sorted_indices_by_* return the
+ full collation indices information, not only the sorted indices, such
+ that the caller may know the language set in collation structure.
+ In get_converter_indices_sorted_by_*, get the language from
+ sorted_indices_by_* collation indices information and pass it through
+ an argument pointer reference.
+ Update callers.
+
+ * tp/Texinfo/XS/main/get_perl_info.c
+ (get_language_document_hv_sorted_indices),
+ tp/Texinfo/XS/convert/ConvertXS.xs
+ (get_converter_indices_sorted_by_index)
+ (get_converter_indices_sorted_by_letter): cache sorted indices built
+ as Perl data in Perl data, such as to build the perl data only once,
+ not for every index. The cached data is retrieved with
+ get_language_document_hv_sorted_indices, which also creates the hash
+ where the sorted indices are stored, if needed.
+
2024-04-15 Patrice Dumas <pertusus@free.fr>
* tp/Texinfo/OutputUnits.pm (units_directions),
diff --git a/tp/Texinfo/XS/convert/ConvertXS.xs
b/tp/Texinfo/XS/convert/ConvertXS.xs
index 5ac5ed495b..549df3def7 100644
--- a/tp/Texinfo/XS/convert/ConvertXS.xs
+++ b/tp/Texinfo/XS/convert/ConvertXS.xs
@@ -249,12 +249,13 @@ get_converter_indices_sorted_by_index (SV *converter_sv)
const INDEX_SORTED_BY_INDEX *index_entries_by_index = 0;
HV *converter_hv;
SV **document_sv;
+ char *language;
CODE:
self = get_sv_converter (converter_sv,
"get_converter_indices_sorted_by_index");
if (self)
index_entries_by_index
- = get_converter_indices_sorted_by_index (self);
+ = get_converter_indices_sorted_by_index (self, &language);
converter_hv = (HV *) SvRV (converter_sv);
document_sv = hv_fetch (converter_hv, "document",
@@ -262,29 +263,51 @@ get_converter_indices_sorted_by_index (SV *converter_sv)
RETVAL = 0;
if (document_sv)
{
- /* TODO if the locale is not XS_STRXFRM_COLLATION_LOCALE
- it could be relevant to store the output of
- build_sorted_indices_by_index in
- document_sv->{'sorted_indices_by_index'}->{$lang_key}
- (as in perl) and get it from here instead of rebuilding,
- such that the perl data is only built once and not for
- each index/call to get_converter_indices_sorted_by_letter.
-
- If TEXINFO_XS_CONVERT=1, this is called for Info output.
- */
- SV *indices_information_sv
- = document_indices_information (*document_sv);
-
- if (index_entries_by_index && indices_information_sv
- && SvOK (indices_information_sv))
+ /* The sorted indices are cached in the same place as in Perl code.
+ Either Perl code or XS code is used, so this is for consistency
+ not really for interoperability */
+ /* set to document "sorted_indices_by_index" */
+ HV *language_document_sorted_indices_hv;
+ /* try first to get sorted index cached in document
+ "sorted_indices_by_index".
+ Gather the hash to use to cache too in
+ language_document_sorted_indices_hv, for use if sorted index is
+ not found */
+ if (language)
{
- HV *indices_information_hv
- = (HV *) SvRV (indices_information_sv);
- HV *index_entries_by_index_hv
- = build_sorted_indices_by_index (index_entries_by_index,
- indices_information_hv);
- RETVAL
- = newRV_inc ((SV *) index_entries_by_index_hv);
+ HV *document_hv = (HV *) SvRV (*document_sv);
+ SV *index_entries_by_index_sv
+ = get_language_document_hv_sorted_indices (document_hv,
+ "sorted_indices_by_index", language,
+ &language_document_sorted_indices_hv);
+ if (index_entries_by_index_sv)
+ RETVAL = SvREFCNT_inc (index_entries_by_index_sv);
+ }
+ if (!RETVAL)
+ {
+ /* build the sorted indices from C */
+ SV *indices_information_sv
+ = document_indices_information (*document_sv);
+
+ if (index_entries_by_index && indices_information_sv
+ && SvOK (indices_information_sv))
+ {
+ HV *indices_information_hv
+ = (HV *) SvRV (indices_information_sv);
+ HV *index_entries_by_index_hv
+ = build_sorted_indices_by_index (index_entries_by_index,
+ indices_information_hv);
+ RETVAL
+ = newRV_inc ((SV *) index_entries_by_index_hv);
+ /* the hash for caching was found or created, cache the
+ sorted indices */
+ if (language_document_sorted_indices_hv)
+ {
+ hv_store (language_document_sorted_indices_hv,
+ language, strlen(language),
+ newRV_inc ((SV *) index_entries_by_index_hv), 0);
+ }
+ }
}
}
if (!RETVAL)
@@ -299,12 +322,13 @@ get_converter_indices_sorted_by_letter (SV *converter_sv)
const INDEX_SORTED_BY_LETTER *index_entries_by_letter = 0;
HV *converter_hv;
SV **document_sv;
+ char *language;
CODE:
self = get_sv_converter (converter_sv,
"get_converter_indices_sorted_by_letter");
if (self)
index_entries_by_letter
- = get_converter_indices_sorted_by_letter (self);
+ = get_converter_indices_sorted_by_letter (self, &language);
converter_hv = (HV *) SvRV (converter_sv);
document_sv = hv_fetch (converter_hv, "document",
@@ -312,34 +336,51 @@ get_converter_indices_sorted_by_letter (SV *converter_sv)
RETVAL = 0;
if (document_sv)
{
- /* TODO if the locale is not XS_STRXFRM_COLLATION_LOCALE
- it could be relevant to store the output of
- build_sorted_indices_by_letter in
- document_sv->{'sorted_indices_by_letter'}->{$lang_key}
- (as in perl) and get it from here instead of rebuilding,
- such that the perl data is only built once and not for
- each index/call to get_converter_indices_sorted_by_letter.
-
- This XS interface code is unlikely to be called, as it is
- only for HTML and would correspond to a user calling
- get_converter_indices_sorted_by_letter from perl, which
- would be relevant mainly for reimplementing printindex
- conversion, this is very improbable so there is no much
- reason to implement something better.
- */
- SV *indices_information_sv
- = document_indices_information (*document_sv);
-
- if (index_entries_by_letter && indices_information_sv
- && SvOK (indices_information_sv))
+ /* The sorted indices are cached in the same place as in Perl code.
+ Either Perl code or XS code is used, so this is for consistency
+ not really for interoperability */
+ /* set to document "sorted_indices_by_letter" */
+ HV *language_document_sorted_indices_hv;
+ /* try first to get sorted index cached in document
+ "sorted_indices_by_letter".
+ Gather the hash to use to cache too in
+ language_document_sorted_indices_hv, for use if sorted index is
+ not found */
+ if (language)
+ {
+ HV *document_hv = (HV *) SvRV (*document_sv);
+ SV *index_entries_by_index_sv
+ = get_language_document_hv_sorted_indices (document_hv,
+ "sorted_indices_by_letter", language,
+ &language_document_sorted_indices_hv);
+ if (index_entries_by_index_sv)
+ RETVAL = SvREFCNT_inc (index_entries_by_index_sv);
+ }
+ if (!RETVAL)
{
- HV *indices_information_hv
- = (HV *) SvRV (indices_information_sv);
- HV *index_entries_by_letter_hv
- = build_sorted_indices_by_letter (index_entries_by_letter,
- indices_information_hv);
- RETVAL
- = newRV_inc ((SV *) index_entries_by_letter_hv);
+ /* build the sorted indices from C */
+ SV *indices_information_sv
+ = document_indices_information (*document_sv);
+
+ if (index_entries_by_letter && indices_information_sv
+ && SvOK (indices_information_sv))
+ {
+ HV *indices_information_hv
+ = (HV *) SvRV (indices_information_sv);
+ HV *index_entries_by_letter_hv
+ = build_sorted_indices_by_letter (index_entries_by_letter,
+ indices_information_hv);
+ RETVAL
+ = newRV_inc ((SV *) index_entries_by_letter_hv);
+ /* the hash for caching was found or created, cache the
+ sorted indices */
+ if (language_document_sorted_indices_hv)
+ {
+ hv_store (language_document_sorted_indices_hv,
+ language, strlen(language),
+ newRV_inc ((SV *) index_entries_by_letter_hv),
0);
+ }
+ }
}
}
if (!RETVAL)
diff --git a/tp/Texinfo/XS/convert/convert_html.c
b/tp/Texinfo/XS/convert/convert_html.c
index 92195ac5df..3f83bdacfc 100644
--- a/tp/Texinfo/XS/convert/convert_html.c
+++ b/tp/Texinfo/XS/convert/convert_html.c
@@ -12530,8 +12530,9 @@ convert_printindex_command (CONVERTER *self, const enum
command_id cmd,
char *index_name_cmd_class;
char *alpha_text = 0;
char *non_alpha_text = 0;
+ char *language;
INDEX_SORTED_BY_LETTER *index_entries_by_letter
- = get_converter_indices_sorted_by_letter (self);
+ = get_converter_indices_sorted_by_letter (self, &language);
if (!index_entries_by_letter)
return;
diff --git a/tp/Texinfo/XS/convert/converter.c
b/tp/Texinfo/XS/convert/converter.c
index 90b2283c01..816a5d2975 100644
--- a/tp/Texinfo/XS/convert/converter.c
+++ b/tp/Texinfo/XS/convert/converter.c
@@ -650,43 +650,55 @@ free_comma_index_subentries_tree (ELEMENT_LIST
*element_list)
}
INDEX_SORTED_BY_INDEX *
-get_converter_indices_sorted_by_index (CONVERTER *self)
+get_converter_indices_sorted_by_index (CONVERTER *self, char **language)
{
+ *language = 0;
if (self->document)
{
char *collation_language = 0;
+ COLLATION_INDICES_SORTED_BY_INDEX *collation_sorted_indices;
if (self->conf->COLLATION_LANGUAGE.string)
collation_language = self->conf->COLLATION_LANGUAGE.string;
else if (self->conf->DOCUMENTLANGUAGE_COLLATION.integer > 0
&& self->conf->documentlanguage.string)
collation_language = self->conf->documentlanguage.string;
- return sorted_indices_by_index (self->document,
- &self->error_messages, self->conf,
- self->conf->USE_UNICODE_COLLATION.integer,
- collation_language,
+ collation_sorted_indices
+ = sorted_indices_by_index (self->document,
+ &self->error_messages, self->conf,
+ self->conf->USE_UNICODE_COLLATION.integer,
+ collation_language,
self->conf->XS_STRXFRM_COLLATION_LOCALE.string);
+ if (collation_sorted_indices->type != ctn_locale_collation)
+ *language = collation_sorted_indices->language;
+ return collation_sorted_indices->sorted_indices;
}
return 0;
}
INDEX_SORTED_BY_LETTER *
-get_converter_indices_sorted_by_letter (CONVERTER *self)
+get_converter_indices_sorted_by_letter (CONVERTER *self, char **language)
{
+ *language = 0;
if (self->document)
{
char *collation_language = 0;
+ COLLATION_INDICES_SORTED_BY_LETTER *collation_sorted_indices;
if (self->conf->COLLATION_LANGUAGE.string)
collation_language = self->conf->COLLATION_LANGUAGE.string;
else if (self->conf->DOCUMENTLANGUAGE_COLLATION.integer > 0
&& self->conf->documentlanguage.string)
collation_language = self->conf->documentlanguage.string;
- return sorted_indices_by_letter (self->document,
- &self->error_messages, self->conf,
- self->conf->USE_UNICODE_COLLATION.integer,
- collation_language,
+ collation_sorted_indices
+ = sorted_indices_by_letter (self->document,
+ &self->error_messages, self->conf,
+ self->conf->USE_UNICODE_COLLATION.integer,
+ collation_language,
self->conf->XS_STRXFRM_COLLATION_LOCALE.string);
+ if (collation_sorted_indices->type != ctn_locale_collation)
+ *language = collation_sorted_indices->language;
+ return collation_sorted_indices->sorted_indices;
}
return 0;
}
diff --git a/tp/Texinfo/XS/convert/converter.h
b/tp/Texinfo/XS/convert/converter.h
index 229f51e77e..06256a0bae 100644
--- a/tp/Texinfo/XS/convert/converter.h
+++ b/tp/Texinfo/XS/convert/converter.h
@@ -114,9 +114,10 @@ ELEMENT_LIST *comma_index_subentries_tree (const ELEMENT
*current_entry,
char *separator);
void free_comma_index_subentries_tree (ELEMENT_LIST *element);
-INDEX_SORTED_BY_INDEX *get_converter_indices_sorted_by_index (CONVERTER *self);
+INDEX_SORTED_BY_INDEX *get_converter_indices_sorted_by_index (CONVERTER *self,
+ char **language);
INDEX_SORTED_BY_LETTER *get_converter_indices_sorted_by_letter
- (CONVERTER *self);
+ (CONVERTER *self, char **language);
char *top_node_filename (const CONVERTER *self, const char *document_name);
diff --git a/tp/Texinfo/XS/main/document.c b/tp/Texinfo/XS/main/document.c
index 4e437620f5..f20411c5af 100644
--- a/tp/Texinfo/XS/main/document.c
+++ b/tp/Texinfo/XS/main/document.c
@@ -232,7 +232,7 @@ find_collation_sorted_indices_by_index (
return 0;
}
-INDEX_SORTED_BY_INDEX *
+COLLATION_INDICES_SORTED_BY_INDEX *
sorted_indices_by_index (DOCUMENT *document,
ERROR_MESSAGE_LIST *error_messages,
OPTIONS *options, int use_unicode_collation,
@@ -294,7 +294,7 @@ sorted_indices_by_index (DOCUMENT *document,
use_unicode_collation, collation_language,
collation_locale);
}
- return collation_sorted_indices->sorted_indices;
+ return collation_sorted_indices;
}
static COLLATION_INDICES_SORTED_BY_LETTER *
@@ -343,7 +343,7 @@ find_collation_sorted_indices_by_letter (
return 0;
}
-INDEX_SORTED_BY_LETTER *
+COLLATION_INDICES_SORTED_BY_LETTER *
sorted_indices_by_letter (DOCUMENT *document,
ERROR_MESSAGE_LIST *error_messages,
OPTIONS *options, int use_unicode_collation,
@@ -405,7 +405,7 @@ sorted_indices_by_letter (DOCUMENT *document,
use_unicode_collation, collation_language,
collation_locale);
}
- return collation_sorted_indices->sorted_indices;
+ return collation_sorted_indices;
}
void
diff --git a/tp/Texinfo/XS/main/document.h b/tp/Texinfo/XS/main/document.h
index 4fa0955f6c..fa8f1fe8bd 100644
--- a/tp/Texinfo/XS/main/document.h
+++ b/tp/Texinfo/XS/main/document.h
@@ -36,12 +36,14 @@ const INDICES_SORT_STRINGS *document_indices_sort_strings (
ERROR_MESSAGE_LIST *error_messages,
OPTIONS *options);
-INDEX_SORTED_BY_INDEX *sorted_indices_by_index (DOCUMENT *document,
+COLLATION_INDICES_SORTED_BY_INDEX *sorted_indices_by_index (
+ DOCUMENT *document,
ERROR_MESSAGE_LIST *error_messages,
OPTIONS *options, int use_unicode_collation,
const char *collation_language,
const char *collation_locale);
-INDEX_SORTED_BY_LETTER *sorted_indices_by_letter (DOCUMENT *document,
+COLLATION_INDICES_SORTED_BY_LETTER *sorted_indices_by_letter (
+ DOCUMENT *document,
ERROR_MESSAGE_LIST *error_messages,
OPTIONS *options, int use_unicode_collation,
const char *collation_language,
diff --git a/tp/Texinfo/XS/main/get_perl_info.c
b/tp/Texinfo/XS/main/get_perl_info.c
index 7fc39518f1..63bdc731ad 100644
--- a/tp/Texinfo/XS/main/get_perl_info.c
+++ b/tp/Texinfo/XS/main/get_perl_info.c
@@ -1621,3 +1621,45 @@ find_element_from_sv (const CONVERTER *converter, const
DOCUMENT *document_in,
return 0;
}
#undef FETCH
+
+/* returns the sorted index for a LANGUAGE if found.
+ Also returns the hash containing the sorted index languages,
+ associated to KEY in the DOCUMENT_HV, created if it did not exist */
+SV *
+get_language_document_hv_sorted_indices (HV *document_hv, const char *key,
+ const char *language, HV **out_sorted_indices_hv)
+{
+ SV **sorted_indices_sv;
+ HV *sorted_indices_hv;
+
+ dTHX;
+
+ sorted_indices_sv = hv_fetch (document_hv, key, strlen (key), 0);
+
+ if (!sorted_indices_sv)
+ {
+ SV *new_sorted_indices_sv;
+
+ sorted_indices_hv = newHV ();
+ new_sorted_indices_sv = newRV_noinc ((SV *) sorted_indices_hv);
+ hv_store (document_hv, key, strlen (key), new_sorted_indices_sv, 0);
+ *out_sorted_indices_hv = sorted_indices_hv;
+ }
+ else
+ {
+ SV **language_sv;
+
+ sorted_indices_hv = (HV *)SvRV (*sorted_indices_sv);
+ *out_sorted_indices_hv = sorted_indices_hv;
+
+ language_sv = hv_fetch (sorted_indices_hv, language,
+ strlen (language), 0);
+ if (language_sv && SvOK (*language_sv))
+ {
+ return *language_sv;
+ }
+ }
+ return 0;
+}
+
+
diff --git a/tp/Texinfo/XS/main/get_perl_info.h
b/tp/Texinfo/XS/main/get_perl_info.h
index af3bf0e27a..775b7f1d23 100644
--- a/tp/Texinfo/XS/main/get_perl_info.h
+++ b/tp/Texinfo/XS/main/get_perl_info.h
@@ -62,4 +62,7 @@ void html_get_direction_icons_sv (const CONVERTER *converter,
const ELEMENT *find_element_from_sv (const CONVERTER *converter,
const DOCUMENT *document_in,
const SV *element_sv, int output_units_descriptor);
+
+SV *get_language_document_hv_sorted_indices (HV *document_hv, const char *key,
+ const char *language, HV **out_sorted_indices_hv);
#endif
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- branch master updated: * tp/Texinfo/XS/convert/converter.c (get_converter_indices_sorted_by_index) (get_converter_indices_sorted_by_letter), tp/Texinfo/XS/main/document.c (sorted_indices_by_index) (sorted_indices_by_letter): have sorted_indices_by_* return the full collation indices information, not only the sorted indices, such that the caller may know the language set in collation structure. In get_converter_indices_sorted_by_*, get the language from sorted_indices_by_* collation indices information and pass i [...],
Patrice Dumas <=