texinfo-commits
[Top][All Lists]
Advanced

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

[no subject]


From: Gavin D. Smith
Date: Mon, 10 Apr 2023 12:16:44 -0400 (EDT)

branch: master
commit b5764856211736727345a73ce24750d8766c2fd3
Author: Gavin Smith <gavinsmith0123@gmail.com>
AuthorDate: Mon Apr 10 17:16:35 2023 +0100

    * tp/Texinfo/XS/parsetexi/api.c (build_perl_array)
    (store_additional_info, element_to_perl_hash)
    (build_target_elements_list, build_internal_xref_list):
    Use av_unshift to extend array followed by av_store instead
    of av_push for each element.
---
 ChangeLog                     |  8 ++++++++
 tp/Texinfo/XS/parsetexi/api.c | 25 +++++++++++++++++--------
 2 files changed, 25 insertions(+), 8 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index aba178b85a..a947473c87 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2023-04-10  Gavin Smith <gavinsmith0123@gmail.com>
+
+       * tp/Texinfo/XS/parsetexi/api.c (build_perl_array)
+       (store_additional_info, element_to_perl_hash)
+       (build_target_elements_list, build_internal_xref_list):
+       Use av_unshift to extend array followed by av_store instead
+       of av_push for each element.
+
 2023-04-10  Gavin Smith <gavinsmith0123@gmail.com>
 
        * tp/Texinfo/XS/parsetexi/api.c (build_perl_array):
diff --git a/tp/Texinfo/XS/parsetexi/api.c b/tp/Texinfo/XS/parsetexi/api.c
index 5da001fb38..4ce81f1d77 100644
--- a/tp/Texinfo/XS/parsetexi/api.c
+++ b/tp/Texinfo/XS/parsetexi/api.c
@@ -279,6 +279,7 @@ build_perl_array (ELEMENT_LIST *e)
 
   av = newAV ();
   sv = newRV_inc ((SV *) av);
+
   for (i = 0; i < e->number; i++)
     {
       if (!e->list[i]->hv)
@@ -292,7 +293,7 @@ build_perl_array (ELEMENT_LIST *e)
               element_to_perl_hash (e->list[i]);
             }
         }
-      av_push (av, newRV_inc ((SV *) e->list[i]->hv));
+      av_store (av, i, newRV_inc ((SV *) e->list[i]->hv));
     }
   return sv;
 }
@@ -371,6 +372,8 @@ store_additional_info (ELEMENT *e, ASSOCIATED_INFO* a, char 
*key)
               int j;
               AV *av;
               av = newAV ();
+              av_unshift (av, f->contents.number);
+
               STORE(newRV_inc ((SV *)av));
               /* An array of strings or integers. */
               for (j = 0; j < f->contents.number; j++)
@@ -380,18 +383,18 @@ store_additional_info (ELEMENT *e, ASSOCIATED_INFO* a, 
char *key)
                   if (k)
                     {
                       IV value = (IV) (intptr_t) k->value;
-                      av_push (av, newSViv (value));
+                      av_store (av, j, newSViv (value));
                     }
                   else if (f->contents.list[j]->text.end > 0)
                     {
                       SV *sv = newSVpv_utf8 (f->contents.list[j]->text.text,
                                              f->contents.list[j]->text.end);
-                      av_push (av, sv);
+                      av_store (av, j, sv);
                     }
                   else
                     {
                       /* Empty strings permitted. */
-                      av_push (av, newSVpv ("", 0));
+                      av_store (av, j, newSVpv ("", 0));
                     }
                 }
               break;
@@ -571,12 +574,14 @@ element_to_perl_hash (ELEMENT *e)
 
       av = newAV ();
       sv = newRV_inc ((SV *) av);
+      av_unshift (av, e->contents.number);
+
       hv_store (e->hv, "contents", strlen ("contents"), sv, HSH_contents);
       for (i = 0; i < e->contents.number; i++)
         {
           element_to_perl_hash (e->contents.list[i]);
           sv = newRV_inc ((SV *) e->contents.list[i]->hv);
-          av_push (av, sv);
+          av_store (av, i, sv);
         }
     }
 
@@ -587,12 +592,14 @@ element_to_perl_hash (ELEMENT *e)
 
       av = newAV ();
       sv = newRV_inc ((SV *) av);
+      av_unshift (av, e->args.number);
+
       hv_store (e->hv, "args", strlen ("args"), sv, HSH_args);
       for (i = 0; i < e->args.number; i++)
         {
           element_to_perl_hash (e->args.list[i]);
           sv = newRV_inc ((SV *) e->args.list[i]->hv);
-          av_push (av, sv);
+          av_store (av, i, sv);
         }
     }
 
@@ -664,11 +671,12 @@ build_target_elements_list (void)
   dTHX;
 
   target_array = newAV ();
+  av_unshift (target_array, labels_number);
 
   for (i = 0; i < labels_number; i++)
     {
       sv = newRV_inc (target_elements_list[i]->hv);
-      av_push (target_array, sv);
+      av_store (target_array, i, sv);
     }
 
   return target_array;
@@ -684,11 +692,12 @@ build_internal_xref_list (void)
   dTHX;
 
   list_av = newAV ();
+  av_unshift (list_av, internal_xref_number);
 
   for (i = 0; i < internal_xref_number; i++)
     {
       sv = newRV_inc (internal_xref_list[i]->hv);
-      av_push (list_av, sv);
+      av_store (list_av, i, sv);
     }
 
   return list_av;



reply via email to

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