texinfo-commits
[Top][All Lists]
Advanced

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

[no subject]


From: Patrice Dumas
Date: Mon, 13 Nov 2023 09:05:14 -0500 (EST)

branch: master
commit 3bbb5a72b413fc13411a972599f14f2ea01e8069
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Mon Nov 13 14:17:02 2023 +0100

    * tp/Texinfo/XS/parsetexi/def.c (split_delimiters, split_def_args),
    tp/Texinfo/XS/structuring_transfo/transformations.c
    (protect_first_parenthesis, protect_text)
    (protect_hashchar_at_line_beginning_internal): call relocate source
    marks only if there are source marks.  Do not initialize variables
    that do not need to be.
---
 ChangeLog                                          |   9 ++
 tp/Texinfo/XS/parsetexi/def.c                      |  49 +++++---
 .../XS/structuring_transfo/transformations.c       | 126 +++++++++++----------
 3 files changed, 109 insertions(+), 75 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 73eb7533d2..bfc220f409 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2023-11-13  Patrice Dumas  <pertusus@free.fr>
+
+       * tp/Texinfo/XS/parsetexi/def.c (split_delimiters, split_def_args),
+       tp/Texinfo/XS/structuring_transfo/transformations.c
+       (protect_first_parenthesis, protect_text)
+       (protect_hashchar_at_line_beginning_internal): call relocate source
+       marks only if there are source marks.  Do not initialize variables
+       that do not need to be.
+
 2023-11-12  Patrice Dumas  <pertusus@free.fr>
 
        * tp/Texinfo/XS/convert/converter.c (register_converter),
diff --git a/tp/Texinfo/XS/parsetexi/def.c b/tp/Texinfo/XS/parsetexi/def.c
index 211d4f3880..d954877954 100644
--- a/tp/Texinfo/XS/parsetexi/def.c
+++ b/tp/Texinfo/XS/parsetexi/def.c
@@ -214,9 +214,10 @@ split_delimiters (ELEMENT *current, int starting_idx)
       ELEMENT *new;
       int len;
       /* count UTF-8 encoded Unicode characters for source marks locations */
-      size_t current_position = 0;
       uint8_t *u8_text = 0;
+      size_t current_position;
       uint8_t *u8_p;
+      size_t u8_len;
 
       if (e->type != ET_NONE
           || e->text.end == 0)
@@ -224,13 +225,16 @@ split_delimiters (ELEMENT *current, int starting_idx)
       p = e->text.text;
 
       if (e->source_mark_list.number)
-        u8_text = u8_strconv_from_encoding (p, "UTF-8",
+        {
+          u8_text = u8_strconv_from_encoding (p, "UTF-8",
                                             iconveh_question_mark);
-      u8_p = u8_text;
+          u8_p = u8_text;
+
+          current_position = 0;
+        }
 
       while (1)
         {
-          size_t u8_len = 0;
           if (strchr (chars, *p))
             {
               new = new_element (ET_delimiter);
@@ -240,9 +244,11 @@ split_delimiters (ELEMENT *current, int starting_idx)
                 {
                   u8_len = u8_mbsnlen (u8_p, 1);
                   u8_p += u8_len;
-                }
-              current_position = relocate_source_marks 
(&(e->source_mark_list), new,
+
+                  current_position
+                   = relocate_source_marks (&(e->source_mark_list), new,
                                                  current_position, u8_len);
+                }
 
               insert_into_contents (current, new, i++);
               add_extra_string_dup (new, "def_role", "delimiter");
@@ -259,9 +265,11 @@ split_delimiters (ELEMENT *current, int starting_idx)
             {
               u8_len = u8_mbsnlen (u8_p, len);
               u8_p += u8_len;
-            }
-          current_position = relocate_source_marks (&(e->source_mark_list), 
new,
+
+             current_position
+               = relocate_source_marks (&(e->source_mark_list), new,
                                           current_position, u8_len);
+            }
 
           insert_into_contents (current, new, i++);
           if (!*(p += len))
@@ -286,9 +294,10 @@ split_def_args (ELEMENT *current, int starting_idx)
       ELEMENT *new;
       int len;
       /* count UTF-8 encoded Unicode characters for source marks locations */
-      size_t current_position = 0;
       uint8_t *u8_text = 0;
+      size_t current_position;
       uint8_t *u8_p;
+      size_t u8_len;
 
       if (e->type == ET_bracketed_arg)
         {
@@ -302,13 +311,16 @@ split_def_args (ELEMENT *current, int starting_idx)
       p = e->text.text;
 
       if (e->source_mark_list.number)
-        u8_text = u8_strconv_from_encoding (p, "UTF-8",
-                                            iconveh_question_mark);
-      u8_p = u8_text;
+        {
+          u8_text = u8_strconv_from_encoding (p, "UTF-8",
+                                              iconveh_question_mark);
+          u8_p = u8_text;
+
+          current_position = 0;
+        }
 
       while (1)
         {
-          size_t u8_len = 0;
           len = strspn (p, whitespace_chars);
           if (len)
             {
@@ -320,15 +332,18 @@ split_def_args (ELEMENT *current, int starting_idx)
               len = strcspn (p, whitespace_chars);
               new = new_element (ET_NONE);
             }
+
+          text_append_n (&new->text, p, len);
+
           if (u8_text)
             {
               u8_len = u8_mbsnlen (u8_p, len);
               u8_p += u8_len;
-            }
 
-          text_append_n (&new->text, p, len);
-          current_position = relocate_source_marks (&(e->source_mark_list), 
new,
-                                current_position, u8_len);
+              current_position
+                = relocate_source_marks (&(e->source_mark_list), new,
+                                         current_position, u8_len);
+            }
           insert_into_contents (current, new, i++);
           if (!*(p += len))
             break;
diff --git a/tp/Texinfo/XS/structuring_transfo/transformations.c 
b/tp/Texinfo/XS/structuring_transfo/transformations.c
index 3a368d0740..2033a1d362 100644
--- a/tp/Texinfo/XS/structuring_transfo/transformations.c
+++ b/tp/Texinfo/XS/structuring_transfo/transformations.c
@@ -109,27 +109,27 @@ protect_first_parenthesis (ELEMENT *element)
            = new_asis_command_with_text ("(", content->parent, content->type);
           ELEMENT *removed = 0;
           /* count UTF-8 encoded Unicode characters for source marks locations 
*/
-          size_t current_position = 0;
           uint8_t *u8_text = 0;
-          uint8_t *u8_p = 0;
-          size_t u8_len = 0;
+          size_t current_position;
+          uint8_t *u8_p;
+          size_t u8_len;
 
           if (content->source_mark_list.number)
             {
               u8_text = u8_strconv_from_encoding (p, "UTF-8",
                                                iconveh_question_mark);
               u8_p = u8_text;
-            }
 
-          if (u8_text)
-            {
+              current_position = 0;
+
               u8_len = u8_mbsnlen (u8_p, 1);
               u8_p += u8_len;
-            }
-          current_position
-            = relocate_source_marks (&(content->source_mark_list),
+
+              current_position
+                = relocate_source_marks (&(content->source_mark_list),
                               new_command->args.list[0]->contents.list[0],
                                      current_position, u8_len);
+            }
 
           if (!*(p+1))
             /* should be the same as content */
@@ -137,25 +137,24 @@ protect_first_parenthesis (ELEMENT *element)
           else
             {
               /* remove leading open brace */
-              char *new_text = strdup (p+1);
-              SOURCE_MARK_LIST source_mark_list = content->source_mark_list;
-              memset (&(content->source_mark_list), 0,
-                      sizeof (SOURCE_MARK_LIST));
-
               text_reset (&content->text);
-              text_append (&content->text, new_text);
-              free (new_text);
+              text_append (&content->text, p+1);
 
-              /* relocate all the remaining source marks */
               if (u8_text)
                 {
+                  /* relocate all the remaining source marks */
+                  SOURCE_MARK_LIST source_mark_list = 
content->source_mark_list;
+                  memset (&(content->source_mark_list), 0,
+                      sizeof (SOURCE_MARK_LIST));
+
                   u8_len = u8_mbsnlen (u8_p, u8_strlen (u8_p));
                   u8_p += u8_len;
-                }
-              current_position
-                = relocate_source_marks (&source_mark_list,
-                   content, current_position, u8_len);
-              free (source_mark_list.list);
+
+                  current_position
+                    = relocate_source_marks (&source_mark_list,
+                       content, current_position, u8_len);
+                  free (source_mark_list.list);
+               }
             }
           insert_into_contents (element, new_command, i);
           free (u8_text);
@@ -1310,20 +1309,22 @@ protect_text (ELEMENT *current, char *to_protect)
       ELEMENT_LIST *container = new_list();
       char *p = current->text.text;
       /* count UTF-8 encoded Unicode characters for source marks locations */
-      size_t current_position = 0;
       uint8_t *u8_text = 0;
+      size_t current_position;
       uint8_t *u8_p = 0;
+      size_t u8_len;
 
       if (current->source_mark_list.number)
         {
           u8_text = u8_strconv_from_encoding (p, "UTF-8",
                                             iconveh_question_mark);
           u8_p = u8_text;
+
+          current_position = 0;
         }
 
       while (*p)
         {
-          size_t u8_len = 0;
           int leading_nr = strcspn (p, to_protect);
           ELEMENT *text_elt = new_element (current->type);
           text_elt->parent = current->parent;
@@ -1341,11 +1342,12 @@ protect_text (ELEMENT *current, char *to_protect)
             {
               u8_len = u8_mbsnlen (u8_p, leading_nr);
               u8_p += u8_len;
+
+              current_position
+                = relocate_source_marks (&(current->source_mark_list),
+                                        text_elt,
+                                        current_position, u8_len);
             }
-          current_position
-            = relocate_source_marks (&(current->source_mark_list),
-                                     text_elt,
-                                     current_position, u8_len);
 
           if (leading_nr || text_elt->source_mark_list.number)
             add_to_element_list (container, text_elt);
@@ -1371,12 +1373,12 @@ protect_text (ELEMENT *current, char *to_protect)
                         {
                           u8_len = u8_mbsnlen (u8_p, 1);
                           u8_p += u8_len;
-                        }
-                      current_position
-                       = relocate_source_marks (&(current->source_mark_list),
-                                                comma,
-                                                current_position, u8_len);
 
+                        current_position
+                          = relocate_source_marks 
(&(current->source_mark_list),
+                                                   comma,
+                                                   current_position, u8_len);
+                        }
                     }
                   p += to_protect_nr;
                 }
@@ -1392,11 +1394,12 @@ protect_text (ELEMENT *current, char *to_protect)
                     {
                       u8_len = u8_mbsnlen (u8_p, to_protect_nr);
                       u8_p += u8_len;
-                    }
-                  current_position
-                     = relocate_source_marks (&(current->source_mark_list),
+
+                      current_position
+                       = relocate_source_marks (&(current->source_mark_list),
                                 new_command->args.list[0]->contents.list[0],
                                               current_position, u8_len);
+                    }
                   p += to_protect_nr;
                   *p = saved;
                 }
@@ -1524,20 +1527,23 @@ protect_hashchar_at_line_beginning_internal (const char 
*type,
                           ELEMENT *arg = new_element (ET_brace_command_arg);
                           /* count UTF-8 encoded Unicode characters for
                              source marks locations */
-                          size_t current_position = 0;
                           uint8_t *u8_text = 0;
-                          uint8_t *u8_p = 0;
-                          size_t u8_len = 0;
-                          SOURCE_MARK_LIST source_mark_list
-                             = current->source_mark_list;
-                          memset (&(current->source_mark_list), 0,
-                                  sizeof (SOURCE_MARK_LIST));
+                          size_t current_position;
+                          uint8_t *u8_p;
+                          size_t u8_len;
+                          SOURCE_MARK_LIST source_mark_list;
 
-                          if (source_mark_list.number)
+                          if (current->source_mark_list.number)
                             {
+                              source_mark_list = current->source_mark_list;
+                              memset (&(current->source_mark_list), 0,
+                                  sizeof (SOURCE_MARK_LIST));
+
                               u8_text = u8_strconv_from_encoding (p, "UTF-8",
                                               iconveh_question_mark);
                               u8_p = u8_text;
+
+                              current_position = 0;
                             }
 
                           /* NOTE not exactly the perl code, but use similar
@@ -1556,11 +1562,12 @@ protect_hashchar_at_line_beginning_internal (const char 
*type,
                             {
                               u8_len = u8_mbsnlen (u8_p, leading_spaces_nr);
                               u8_p += u8_len;
-                            }
-                          current_position
-                            = relocate_source_marks (&source_mark_list,
-                                                     leading_spaces,
+
+                              current_position
+                                = relocate_source_marks (&source_mark_list,
+                                                         leading_spaces,
                                                      current_position, u8_len);
+                            }
 
                           if (leading_spaces_nr
                               || leading_spaces->source_mark_list.number)
@@ -1580,27 +1587,30 @@ protect_hashchar_at_line_beginning_internal (const char 
*type,
                             {
                               u8_len = u8_mbsnlen (u8_p, 1);
                               u8_p += u8_len;
-                            }
-                          current_position
-                            = relocate_source_marks (&source_mark_list,
-                                                     hashchar,
+
+                              current_position
+                                = relocate_source_marks (&source_mark_list,
+                                                         hashchar,
                                                      current_position, u8_len);
+                            }
 
                           text_reset (&current->text);
                           text_append (&current->text, p);
                           free (current_text);
 
-                          /* relocate all the remaining source marks */
                           if (u8_text)
                             {
+                              /* relocate all the remaining source marks */
                               u8_len = u8_mbsnlen (u8_p, u8_strlen (u8_p));
                               u8_p += u8_len;
+
+                              current_position
+                                = relocate_source_marks (&source_mark_list,
+                                          current, current_position, u8_len);
+
+                              free (source_mark_list.list);
+                              free (u8_text);
                             }
-                          current_position
-                            = relocate_source_marks (&source_mark_list,
-                                      current, current_position, u8_len);
-                          free (source_mark_list.list);
-                          free (u8_text);
 
                           add_to_element_list (container, current);
                           return container;



reply via email to

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