texinfo-commits
[Top][All Lists]
Advanced

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

[no subject]


From: Patrice Dumas
Date: Tue, 9 Jan 2024 08:08:15 -0500 (EST)

branch: master
commit d68472208fe0eb65fe6ec7b24db90d13914c7388
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Mon Jan 8 11:12:47 2024 +0100

    * tp/Texinfo/XS/structuring_transfo/StructuringTransfoXS.xs
    (index_entry_element_sort_string): free sort_string.
    
    * tp/Texinfo/Convert/Text.pm (text_accents, brace_no_arg_command)
    (_convert): use 'set_case' for case, that can be positive for upper
    casing and negative for lower casing instead of 'sc', as in XS.
    
    * tp/Texinfo/Structuring.pm (setup_sortable_index_entries): rename
    $options as $convert_text_options and set code directly and pass
    $convert_text_options directly instead of copying.
    
    * tp/Texinfo/Convert/LaTeX.pm (_prepare_indices, _index_entry): set
    index_formatting_text_options state once for all in _prepare_indices
    instead of for each index entry.  Set code directly in the state and
    pass the state insetad of copying it in _index_entry.
    
    * tp/Texinfo/XS/main/convert_to_text.c (destroy_text_options),
    tp/Texinfo/XS/main/get_perl_info.c (copy_sv_options_for_convert_text):
    if an XS converter is associated to the text optins, set it in
    TEXT_OPTIONS and directly use its conf for other_converter_options. Do
    not destroy other_converter_options if converter is set.
    Set self_converter_options only if other_converter_options is not set.
    
    * tp/Texinfo/XS/main/convert_to_text.c (text_accents_options)
    (text_options): use static text_accents_options in text_options
    instead of allocating and freeing.
---
 ChangeLog                                          | 29 ++++++++++++++++++++
 tp/TODO                                            |  1 +
 tp/Texinfo/Convert/LaTeX.pm                        |  8 +++---
 tp/Texinfo/Convert/Text.pm                         | 32 ++++++++++++----------
 tp/Texinfo/Structuring.pm                          | 18 ++++++------
 tp/Texinfo/XS/main/convert_to_text.c               | 13 +++++----
 tp/Texinfo/XS/main/convert_to_text.h               |  4 ++-
 tp/Texinfo/XS/main/get_perl_info.c                 | 30 ++++++++++++++------
 .../XS/structuring_transfo/StructuringTransfoXS.xs |  5 +++-
 9 files changed, 96 insertions(+), 44 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 417ffd4736..eaab480d69 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,32 @@
+2024-01-08  Patrice Dumas  <pertusus@free.fr>
+
+       * tp/Texinfo/XS/structuring_transfo/StructuringTransfoXS.xs
+       (index_entry_element_sort_string): free sort_string.
+
+       * tp/Texinfo/Convert/Text.pm (text_accents, brace_no_arg_command)
+       (_convert): use 'set_case' for case, that can be positive for upper
+       casing and negative for lower casing instead of 'sc', as in XS.
+
+       * tp/Texinfo/Structuring.pm (setup_sortable_index_entries): rename
+       $options as $convert_text_options and set code directly and pass
+       $convert_text_options directly instead of copying.
+
+       * tp/Texinfo/Convert/LaTeX.pm (_prepare_indices, _index_entry): set
+       index_formatting_text_options state once for all in _prepare_indices
+       instead of for each index entry.  Set code directly in the state and
+       pass the state insetad of copying it in _index_entry.
+
+       * tp/Texinfo/XS/main/convert_to_text.c (destroy_text_options),
+       tp/Texinfo/XS/main/get_perl_info.c (copy_sv_options_for_convert_text):
+       if an XS converter is associated to the text optins, set it in
+       TEXT_OPTIONS and directly use its conf for other_converter_options. Do
+       not destroy other_converter_options if converter is set. 
+       Set self_converter_options only if other_converter_options is not set.
+
+       * tp/Texinfo/XS/main/convert_to_text.c (text_accents_options)
+       (text_options): use static text_accents_options in text_options
+       instead of allocating and freeing.
+
 2024-01-07  Patrice Dumas  <pertusus@free.fr>
 
        * tp/Texinfo/Structuring.pm (setup_index_entry_keys_formatting):
diff --git a/tp/TODO b/tp/TODO
index 179ba95fe8..9a0f5f639f 100644
--- a/tp/TODO
+++ b/tp/TODO
@@ -657,6 +657,7 @@ tidy -qe *.html
 profiling: package on debian:
 libdevel-nytprof-perl
 In doc:
+perl -d:NYTProf ../tp/texi2any.pl texinfo.texi --html
 perl -d:NYTProf ../tp/texi2any.pl texinfo.texi
 nytprofhtml
 # firefox nytprof/index.html
diff --git a/tp/Texinfo/Convert/LaTeX.pm b/tp/Texinfo/Convert/LaTeX.pm
index e178016a0e..57fc65b6ab 100644
--- a/tp/Texinfo/Convert/LaTeX.pm
+++ b/tp/Texinfo/Convert/LaTeX.pm
@@ -940,6 +940,8 @@ sub _prepare_indices($)
 
   my $index_names = $self->{'indices_information'};
   if ($index_names) {
+    $self->{'index_formatting_text_options'}
+      = Texinfo::Structuring::setup_index_entry_keys_formatting($self);
     my $merged_index_entries
         = Texinfo::Structuring::merge_indices($index_names);
     # select non empty indices
@@ -2429,8 +2431,6 @@ sub _index_entry($$)
     if ($index_info->{'in_code'}) {
       $in_code = 1;
     }
-    my $options
-      = Texinfo::Structuring::setup_index_entry_keys_formatting($self);
     my @subindex_commands = ($element);
     my $current_element = $element;
     while ($current_element->{'extra'}
@@ -2452,12 +2452,12 @@ sub _index_entry($$)
         pop @{$self->{'formatting_context'}->[-1]->{'code'}};
       }
       # always setup a string to sort with as we may use commands
-      my $convert_to_text_options = {%$options, 'code' => $in_code};
+      $self->{'index_formatting_text_options'}->{'code'} = $in_code;
       my $sort_string
            = Texinfo::Structuring::index_entry_element_sort_string(
                                           $self, $entry,
                                           $subindex_command,
-                                          $convert_to_text_options, 1);
+                            $self->{'index_formatting_text_options'}, 1);
       my $result = '';
       if (defined($sort_string)) {
         # | in sort key breaks with hyperref
diff --git a/tp/Texinfo/Convert/Text.pm b/tp/Texinfo/Convert/Text.pm
index b98766b677..17082d1881 100644
--- a/tp/Texinfo/Convert/Text.pm
+++ b/tp/Texinfo/Convert/Text.pm
@@ -269,10 +269,9 @@ sub text_accents($;$$)
 
   my ($contents_element, $stack)
       = Texinfo::Convert::Utils::find_innermost_accent_contents($accent);
-
   my $options = {};
   $options->{'enabled_encoding'} = $encoding if (defined($encoding));
-  $options->{'sc'} = $set_case if (defined($set_case));
+  $options->{'set_case'} = $set_case if (defined($set_case));
   my $text = convert_to_text($contents_element, $options);
 
   my $result = Texinfo::Convert::Unicode::encoded_accents(undef, $text,
@@ -321,13 +320,14 @@ sub brace_no_arg_command($;$)
     }
   }
   if ($options and $Texinfo::Commands::letter_no_arg_commands{$command}) {
-    if ($options->{'sc'}) {
-      $result = uc($result);
-    # NOTE does not seems to be set anywhere.  Not a big deal to keep it,
-    # but if it become used, it should be checked whether code elsewhere
-    # should be changed to look for lc too.  XS should be ok.
-    } elsif ($options->{'lc'}) {
-      $result = lc($result);
+    if ($options->{'set_case'}) {
+      if ($options->{'set_case'} > 0) {
+        $result = uc($result);
+      # NOTE does not seems to be decreased/set to negative anywhere, but
+      # should work ok if it is.
+      } else {
+        $result = lc($result);
+      }
     }
   }
   return $result;
@@ -531,8 +531,12 @@ sub _convert($;$)
       if ((! defined($element->{'type'})
            or $element->{'type'} ne 'raw')
           and !$options->{'_raw_state'}) {
-        if ($options->{'sc'}) {
-          $result = uc($result);
+        if ($options->{'set_case'}) {
+          if ($options->{'set_case'} > 0) {
+            $result = uc($result);
+          } else {
+            $result = lc($result);
+          }
         }
         if (!$options->{'_code_state'}) {
           $result =~ s/``/"/g;
@@ -569,7 +573,7 @@ sub _convert($;$)
     # commands with braces
     } elsif ($accent_commands{$element->{'cmdname'}}) {
       my $result = text_accents($element, $options->{'enabled_encoding'},
-                                $options->{'sc'});
+                                $options->{'set_case'});
       return $result;
     } elsif ($element->{'cmdname'} eq 'image') {
       $options->{'_code_state'}++;
@@ -638,7 +642,7 @@ sub _convert($;$)
                                                   $element->{'cmdname'}})))) {
       my $result;
       my $in_code;
-      $options->{'sc'}++ if ($element->{'cmdname'} eq 'sc');
+      $options->{'set_case'}++ if ($element->{'cmdname'} eq 'sc');
       if ($Texinfo::Commands::brace_code_commands{$element->{'cmdname'}}
                or $Texinfo::Commands::math_commands{$element->{'cmdname'}}) {
         $in_code = 1;
@@ -646,7 +650,7 @@ sub _convert($;$)
       $options->{'_code_state'}++ if ($in_code);
       $result = _convert($element->{'args'}->[0], $options);
       $options->{'_code_state'}-- if ($in_code);
-      $options->{'sc'}-- if ($element->{'cmdname'} eq 'sc');
+      $options->{'set_case'}-- if ($element->{'cmdname'} eq 'sc');
       return $result;
     # block commands
     } elsif ($element->{'cmdname'} eq 'quotation'
diff --git a/tp/Texinfo/Structuring.pm b/tp/Texinfo/Structuring.pm
index abbb3fb4e8..bb92d614e7 100644
--- a/tp/Texinfo/Structuring.pm
+++ b/tp/Texinfo/Structuring.pm
@@ -114,11 +114,10 @@ our %XS_overrides = (
   "Texinfo::Structuring::_XS_unsplit"
     => "Texinfo::StructTransfXS::unsplit",
 
-  # TODO the XS override is slower than the perl function.
-  # One possible reason could be that the text options are read
+  # TODO the text options are read
   # from perl for each entry instead of once for each index.
-  #"Texinfo::Structuring::index_entry_element_sort_string"
-  #  => "Texinfo::StructTransfXS::index_entry_element_sort_string",
+  "Texinfo::Structuring::index_entry_element_sort_string"
+    => "Texinfo::StructTransfXS::index_entry_element_sort_string",
 
   # Not useful for HTML as functions, as the calling functions are
   # already overriden
@@ -2471,19 +2470,20 @@ sub setup_sortable_index_entries($$$$$;$)
   return $index_sortable_index_entries, $collator, $index_entries_sort_strings
     unless ($index_entries);
 
-  my $options = setup_index_entry_keys_formatting($customization_information);
+  my $convert_text_options
+    = setup_index_entry_keys_formatting($customization_information);
   $index_sortable_index_entries = {};
   foreach my $index_name (keys(%$index_entries)) {
     my $sortable_index_entries = [];
     foreach my $index_entry (@{$index_entries->{$index_name}}) {
       my $entry_index_name = $index_entry->{'index_name'};
       my $main_entry_element = $index_entry->{'entry_element'};
-      my $convert_to_text_options = {%$options,
-        'code' => $indices_information->{$entry_index_name}->{'in_code'}};
+      $convert_text_options->{'code'}
+        = $indices_information->{$entry_index_name}->{'in_code'};
       my ($entry_key, $sort_entry_key)
         = _index_entry_element_sort_string_key($customization_information,
                                    $index_entry, $main_entry_element,
-                                  $convert_to_text_options, $entries_collator);
+                                   $convert_text_options, $entries_collator);
       my @entry_keys;
       my @sort_entry_keys;
       if ($entry_key !~ /\S/) {
@@ -2511,7 +2511,7 @@ sub setup_sortable_index_entries($$$$$;$)
         $subentry = $subentry->{'extra'}->{'subentry'};
         my ($subentry_key, $sort_subentry_key)
               = 
_index_entry_element_sort_string_key($customization_information,
-                             $index_entry, $subentry, $convert_to_text_options,
+                             $index_entry, $subentry, $convert_text_options,
                                 $entries_collator);
         if ($subentry_key !~ /\S/) {
           my $entry_cmdname = $main_entry_element->{'cmdname'};
diff --git a/tp/Texinfo/XS/main/convert_to_text.c 
b/tp/Texinfo/XS/main/convert_to_text.c
index 46004fc579..313093bad0 100644
--- a/tp/Texinfo/XS/main/convert_to_text.c
+++ b/tp/Texinfo/XS/main/convert_to_text.c
@@ -126,7 +126,8 @@ destroy_text_options (TEXT_OPTIONS *text_options)
   free (text_options->encoding);
   free (text_options->expanded_formats);
   free_strings_list (&text_options->include_directories);
-  if (text_options->other_converter_options)
+  if (text_options->other_converter_options
+      && !text_options->converter)
     {
       free_options (text_options->other_converter_options);
       free (text_options->other_converter_options);
@@ -144,7 +145,7 @@ destroy_text_options (TEXT_OPTIONS *text_options)
   tico_option_name(ASCII_GLYPH) \
   tico_option_name(TEST)
 
-/* note that nothing is copied */
+/* note that nothing is allocated, except for the TEXT_OPTIONS themselves */
 TEXT_OPTIONS *
 copy_options_for_convert_text (CONVERTER *self,
                                int enable_encoding_if_not_ascii)
@@ -181,6 +182,8 @@ copy_options_for_convert_text (CONVERTER *self,
   return options;
 }
 
+static TEXT_OPTIONS text_accents_options;
+
 /* format an accent command and nested accents within as Text. */
 char *
 text_accents (const ELEMENT *accent, char *encoding, int set_case)
@@ -188,10 +191,9 @@ text_accents (const ELEMENT *accent, char *encoding, int 
set_case)
   ACCENTS_STACK *accent_stack = find_innermost_accent_contents (accent);
   char *arg_text;
   char *result;
-  TEXT_OPTIONS *text_options = new_text_options ();
+  TEXT_OPTIONS *text_options = &text_accents_options;
 
-  if (encoding)
-    text_options->encoding = strdup (encoding);
+  text_options->encoding = encoding;
   text_options->set_case = set_case;
 
   if (accent_stack->argument)
@@ -206,7 +208,6 @@ text_accents (const ELEMENT *accent, char *encoding, int 
set_case)
     result = ascii_accents_internal (arg_text, &accent_stack->stack, set_case);
   free (arg_text);
   destroy_accent_stack (accent_stack);
-  destroy_text_options (text_options);
   return result;
 }
 
diff --git a/tp/Texinfo/XS/main/convert_to_text.h 
b/tp/Texinfo/XS/main/convert_to_text.h
index f3c12dcee9..7d72347ba2 100644
--- a/tp/Texinfo/XS/main/convert_to_text.h
+++ b/tp/Texinfo/XS/main/convert_to_text.h
@@ -8,7 +8,7 @@
 #include "converter_types.h"
 
 typedef struct TEXT_OPTIONS {
-    int set_case; /* sc and lc */
+    int set_case;
     char *encoding; /* enabled_encoding */
     int code_state; /* code */
     int raw_state;
@@ -19,6 +19,8 @@ typedef struct TEXT_OPTIONS {
     EXPANDED_FORMAT *expanded_formats;
     STRING_LIST include_directories;
     CONVERTER *converter;
+    /* other_converter_options is used if set.  If not set and in some cases
+       self_converter_options, if set, is used. */
     OPTIONS *other_converter_options; /* corresponds to converter passed
                                          to convert_to_text text options.
       same than converter if set, but can be set directly from perl */
diff --git a/tp/Texinfo/XS/main/get_perl_info.c 
b/tp/Texinfo/XS/main/get_perl_info.c
index 984bca7ac0..373a7b9fb8 100644
--- a/tp/Texinfo/XS/main/get_perl_info.c
+++ b/tp/Texinfo/XS/main/get_perl_info.c
@@ -911,7 +911,7 @@ force_conf (CONVERTER *converter, const char *conf, SV 
*value)
 /* output format specific */
 
 /* map hash reference of Convert::Text options to TEXT_OPTIONS */
-/* TODO more to do? */
+/* TODO more to do? set_case? */
 #define FETCH(key) key##_sv = hv_fetch (hv_in, #key, strlen(#key), 0);
 TEXT_OPTIONS *
 copy_sv_options_for_convert_text (SV *sv_in)
@@ -955,15 +955,27 @@ copy_sv_options_for_convert_text (SV *sv_in)
   FETCH(converter)
   if (converter_sv)
     {
-      HV *converter_hv = (HV *) SvRV (*converter_sv);
-      SV **conf_sv = hv_fetch (converter_hv, "conf", strlen ("conf"), 0);
-      if (conf_sv)
-        text_options->other_converter_options
-          = init_copy_sv_options (*conf_sv, 0, 1);
+      CONVERTER *converter = get_sv_converter (*converter_sv, 0);
+      if (converter)
+        {
+          text_options->other_converter_options
+            = converter->conf;
+          text_options->converter = converter;
+        }
+      else
+        {
+          HV *converter_hv = (HV *) SvRV (*converter_sv);
+          SV **conf_sv = hv_fetch (converter_hv, "conf", strlen ("conf"), 0);
+          if (conf_sv)
+            text_options->other_converter_options
+              = init_copy_sv_options (*conf_sv, 0, 1);
+        }
+    }
+  else
+    {
+      text_options->self_converter_options
+       = init_copy_sv_options (sv_in, 0, 1);
     }
-
-  text_options->self_converter_options
-     = init_copy_sv_options (sv_in, 0, 1);
 
   return text_options;
 }
diff --git a/tp/Texinfo/XS/structuring_transfo/StructuringTransfoXS.xs 
b/tp/Texinfo/XS/structuring_transfo/StructuringTransfoXS.xs
index 900f9e9c22..80d48356e6 100644
--- a/tp/Texinfo/XS/structuring_transfo/StructuringTransfoXS.xs
+++ b/tp/Texinfo/XS/structuring_transfo/StructuringTransfoXS.xs
@@ -468,7 +468,10 @@ index_entry_element_sort_string (SV *document_in, SV 
*main_entry_sv, SV *element
        if (!sort_string)
          RETVAL = newSV (0);
        else
-         RETVAL = newSVpv_utf8 (sort_string, 0);
+         {
+           RETVAL = newSVpv_utf8 (sort_string, 0);
+           free (sort_string);
+         }
     OUTPUT:
          RETVAL
 



reply via email to

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