[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
branch master updated: Obstacks for parsetexi
From: |
Gavin D. Smith |
Subject: |
branch master updated: Obstacks for parsetexi |
Date: |
Mon, 10 Apr 2023 12:54:42 -0400 |
This is an automated email from the git hooks/post-receive script.
gavin pushed a commit to branch master
in repository texinfo.
The following commit(s) were added to refs/heads/master by this push:
new c6270b08d9 Obstacks for parsetexi
c6270b08d9 is described below
commit c6270b08d9a85c7d93487cf732c8dee4f66ba9d9
Author: Gavin Smith <gavinsmith0123@gmail.com>
AuthorDate: Mon Apr 10 17:54:33 2023 +0100
Obstacks for parsetexi
* tp/Texinfo/XS/parsetexi/tree.c (alloc_element, alloc_associated_info)
(reset_obstacks): Use obstack allocation for tree elements.
(new_associated_info, new_element): Call new functions.
(destroy_element): Do not call 'free' on obstack-allocated storage.
* tp/Texinfo/XS/parsetexi/api.c (reset_parser_except_conf):
Call reset_obstacks.
(parse_string, parse_piece): Do not create tree elements until
after calling reset_parser_except_conf.
---
ChangeLog | 13 +++++++
tp/Texinfo/XS/parsetexi/api.c | 11 ++++--
tp/Texinfo/XS/parsetexi/tree.c | 88 +++++++++++++++++++++++++++++++++++++++---
tp/Texinfo/XS/parsetexi/tree.h | 2 +
4 files changed, 106 insertions(+), 8 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 6729ff809e..44261863cd 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2023-04-10 Gavin Smith <gavinsmith0123@gmail.com>
+
+ Obstacks for parsetexi
+
+ * tp/Texinfo/XS/parsetexi/tree.c (alloc_element, alloc_associated_info)
+ (reset_obstacks): Use obstack allocation for tree elements.
+ (new_associated_info, new_element): Call new functions.
+ (destroy_element): Do not call 'free' on obstack-allocated storage.
+ * tp/Texinfo/XS/parsetexi/api.c (reset_parser_except_conf):
+ Call reset_obstacks.
+ (parse_string, parse_piece): Do not create tree elements until
+ after calling reset_parser_except_conf.
+
2023-04-10 Gavin Smith <gavinsmith0123@gmail.com>
* tp/Texinfo/XS/parsetexi/input.c (encode_with_iconv):
diff --git a/tp/Texinfo/XS/parsetexi/api.c b/tp/Texinfo/XS/parsetexi/api.c
index 4ce81f1d77..3945a558f3 100644
--- a/tp/Texinfo/XS/parsetexi/api.c
+++ b/tp/Texinfo/XS/parsetexi/api.c
@@ -157,6 +157,8 @@ reset_parser_except_conf (void)
source_marks_reset_counters ();
free_small_strings ();
+ reset_obstacks ();
+
current_node = current_section = current_part = 0;
}
@@ -242,9 +244,10 @@ parse_text (char *string, int line_nr)
void
parse_string (char *string, int line_nr)
{
- ELEMENT *root_elt = new_element (ET_root_line);
+ ELEMENT *root_elt;
reset_parser_except_conf ();
+ root_elt = new_element (ET_root_line);
input_push_text (strdup (string), line_nr, 0, 0);
Root = parse_texi (root_elt, root_elt);
}
@@ -253,10 +256,12 @@ parse_string (char *string, int line_nr)
void
parse_piece (char *string, int line_nr)
{
- ELEMENT *before_node_section = setup_document_root_and_before_node_section
();
- ELEMENT *document_root = before_node_section->parent;
+ ELEMENT *before_node_section, *document_root;
reset_parser_except_conf ();
+ before_node_section = setup_document_root_and_before_node_section ();
+ document_root = before_node_section->parent;
+
input_push_text (strdup (string), line_nr, 0, 0);
Root = parse_texi (document_root, before_node_section);
}
diff --git a/tp/Texinfo/XS/parsetexi/tree.c b/tp/Texinfo/XS/parsetexi/tree.c
index 4062aab49e..5cb8fc16c8 100644
--- a/tp/Texinfo/XS/parsetexi/tree.c
+++ b/tp/Texinfo/XS/parsetexi/tree.c
@@ -16,6 +16,7 @@
#include <config.h>
#include <stdlib.h>
#include <string.h>
+#include <obstack.h>
#include "errors.h"
#include "tree.h"
@@ -25,10 +26,85 @@
//int element_counter;
+#if 0
+ /* could be used if obstacks not available. delete this code if it is
+ not used eventually. */
+
+# define CHAIN_LENGTH 32
+
+ typedef struct ELEMENT_CHAIN {
+ ELEMENT array[CHAIN_LENGTH];
+ int num;
+ struct ELEMENT_CHAIN *next;
+ struct ELEMENT_CHAIN *prev;
+ } ELEMENT_CHAIN;
+
+ static ELEMENT_CHAIN *element_chain = 0;
+
+ ELEMENT *
+ alloc_element (void)
+ {
+ if (!element_chain)
+ {
+ element_chain = calloc (1, sizeof (ELEMENT_CHAIN));
+ }
+ else if (element_chain->num == CHAIN_LENGTH)
+ {
+ element_chain->next = calloc (1, sizeof (ELEMENT_CHAIN));
+ element_chain->next->prev = element_chain;
+ element_chain = element_chain->next;
+ }
+ return &element_chain->array[element_chain->num++];
+ }
+
+ void
+ chain_free (ELEMENT_CHAIN *chain)
+ {
+ ELEMENT *current, *next;
+
+ current = chain;
+ while (current)
+ {
+ next = current;
+ free (current);
+ current = next;
+ }
+ }
+
+#endif
+
+static struct obstack obs_element;
+static int *obs_element_first = 0;
+
+#define obstack_chunk_alloc malloc
+#define obstack_chunk_free free
+
+void
+reset_obstacks (void)
+{
+ if (obs_element_first)
+ obstack_free (&obs_element, obs_element_first);
+
+ obstack_init (&obs_element);
+ obs_element_first = obstack_alloc (&obs_element, sizeof (int));
+}
+
+static ELEMENT *alloc_element (void)
+{
+ return (ELEMENT *) obstack_alloc (&obs_element, sizeof (ELEMENT));
+}
+
+static ASSOCIATED_INFO *alloc_associated_info (void)
+{
+ return (ASSOCIATED_INFO *) obstack_alloc
+ (&obs_element, sizeof (ASSOCIATED_INFO));
+}
+
+
ASSOCIATED_INFO *
new_associated_info (void)
{
- ASSOCIATED_INFO *info = malloc (sizeof (ASSOCIATED_INFO));
+ ASSOCIATED_INFO *info = alloc_associated_info ();
info->info_number = 0;
info->info_space = 0;
@@ -39,7 +115,7 @@ new_associated_info (void)
ELEMENT *
new_element (enum element_type type)
{
- ELEMENT *e = malloc (sizeof (ELEMENT));
+ ELEMENT *e = alloc_element ();
//element_counter++;
@@ -129,12 +205,14 @@ destroy_element (ELEMENT *e)
free (e->contents.list);
free (e->args.list);
- destroy_associated_info (e->extra_info);
- destroy_associated_info (e->info_info);
+ /* freed in reset_obstacks */
+ /* destroy_associated_info (e->extra_info); */
+ /* destroy_associated_info (e->info_info); */
destroy_source_mark_list (&(e->source_mark_list));
- free (e);
+ /* freed in reset_obstacks */
+ /* free (e); */
}
/* Recursively destroy this element and all data in its descendants. */
diff --git a/tp/Texinfo/XS/parsetexi/tree.h b/tp/Texinfo/XS/parsetexi/tree.h
index 7c646a8ce8..6ca91789f0 100644
--- a/tp/Texinfo/XS/parsetexi/tree.h
+++ b/tp/Texinfo/XS/parsetexi/tree.h
@@ -4,6 +4,8 @@
#include "tree_types.h"
+void reset_obstacks (void);
+
ASSOCIATED_INFO *new_associated_info (void);
ELEMENT *new_element (enum element_type type);
void add_to_element_contents (ELEMENT *parent, ELEMENT *e);
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- branch master updated: Obstacks for parsetexi,
Gavin D. Smith <=