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: Sun, 9 Apr 2023 10:38:21 -0400 (EDT)

branch: master
commit 63744235a04b454873cdc38a47a6646689a50360
Author: Gavin Smith <gavinsmith0123@gmail.com>
AuthorDate: Sun Apr 9 15:38:09 2023 +0100

    * tp/Texinfo/XS/parsetexi/api.c (reset_parser_except_conf):
    Keep a few old values of the 'Root' pointer to avoid calling
    destroy_element_and_children on the main tree, which takes a
    significant length of time.
---
 ChangeLog                     |  7 +++++++
 tp/Texinfo/XS/parsetexi/api.c | 18 +++++++++++++++---
 2 files changed, 22 insertions(+), 3 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 8a3dfea008..531cab479d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2023-04-09  Gavin Smith <gavinsmith0123@gmail.com>
+
+       * tp/Texinfo/XS/parsetexi/api.c (reset_parser_except_conf):
+       Keep a few old values of the 'Root' pointer to avoid calling
+       destroy_element_and_children on the main tree, which takes a
+       significant length of time.
+
 2023-04-09  Gavin Smith <gavinsmith0123@gmail.com>
 
        * README-hacking: mention callgrind for XS modules
diff --git a/tp/Texinfo/XS/parsetexi/api.c b/tp/Texinfo/XS/parsetexi/api.c
index 816d6f7472..2283ee78a8 100644
--- a/tp/Texinfo/XS/parsetexi/api.c
+++ b/tp/Texinfo/XS/parsetexi/api.c
@@ -47,8 +47,6 @@
 #include "errors.h"
 #include "api.h"
 
-ELEMENT *Root;
-
 #ifdef ENABLE_NLS
 
 #define LOCALEDIR DATADIR "/locale"
@@ -115,6 +113,17 @@ reset_floats ()
   floats_number = 0;
 }
 
+ELEMENT *Root;
+
+/* Array to keep old values of Root.  This is a time efficiency to avoid
+   calling destroy_element_and_children.  It is likely the first value
+   of Root is the main parse tree representing the whole document.
+   We keep the references to avoid the appearance of a memory leak. */
+#define MAX_OLD_ROOTS 5
+static ELEMENT *old_roots[MAX_OLD_ROOTS];
+static int n_old_roots = 0;
+
+
 void
 reset_parser_except_conf (void)
 {
@@ -123,7 +132,10 @@ reset_parser_except_conf (void)
   wipe_indices ();
   if (Root)
     {
-      destroy_element_and_children (Root);
+      if (n_old_roots == MAX_OLD_ROOTS)
+        destroy_element_and_children (Root);
+      else
+        old_roots[n_old_roots++] = Root;
       Root = 0;
     }
   wipe_user_commands ();



reply via email to

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