Add MXML_ALLOC_SIZE define (Issue #318)

master
Michael R Sweet 4 weeks ago
parent 0c97db4186
commit 002c34f458
No known key found for this signature in database
GPG Key ID: BE67C75EC81F3244
  1. 6
      CHANGES.md
  2. 12
      mxml-attr.c
  3. 4
      mxml-index.c
  4. 3
      mxml-private.h

@ -5,10 +5,12 @@ Changes in Mini-XML
Changes in Mini-XML 4.0.3
-------------------------
- The configure script now defaults the `DSOFLAGS` value to `LDFLAGS` if not
set (Issue #325)
- Now default the `DSOFLAGS` value to `LDFLAGS` in the configure script
(Issue #325)
- Now install the man page as "mxml4" to allow parallel installation of Mini-XML
4.x and 3.x (Issue #324)
- Added `MXML_ALLOC_SIZE` define to control the allocation increment for
attributes and indices (Issue #318)
- Fixed `mxmlSetDeclarationf` implementation (Issue #322)

@ -250,11 +250,15 @@ mxml_set_attr(mxml_node_t *node, // I - Element node
}
// Add a new attribute...
if ((attr = realloc(node->value.element.attrs, (node->value.element.num_attrs + 1) * sizeof(_mxml_attr_t))) == NULL)
return (false);
if ((node->value.element.num_attrs % MXML_ALLOC_SIZE) == 0)
{
if ((attr = realloc(node->value.element.attrs, (node->value.element.num_attrs + MXML_ALLOC_SIZE) * sizeof(_mxml_attr_t))) == NULL)
return (false);
node->value.element.attrs = attr;
}
node->value.element.attrs = attr;
attr += node->value.element.num_attrs;
attr = node->value.element.attrs + node->value.element.num_attrs;
if ((attr->name = _mxml_strcopy(name)) == NULL)
return (false);

@ -247,7 +247,7 @@ mxmlIndexNew(mxml_node_t *node, // I - XML node tree
{
if (ind->num_nodes >= ind->alloc_nodes)
{
if ((temp = realloc(ind->nodes, (ind->alloc_nodes + 64) * sizeof(mxml_node_t *))) == NULL)
if ((temp = realloc(ind->nodes, (ind->alloc_nodes + MXML_ALLOC_SIZE) * sizeof(mxml_node_t *))) == NULL)
{
// Unable to allocate memory for the index, so abort...
mxmlIndexDelete(ind);
@ -255,7 +255,7 @@ mxmlIndexNew(mxml_node_t *node, // I - XML node tree
}
ind->nodes = temp;
ind->alloc_nodes += 64;
ind->alloc_nodes += MXML_ALLOC_SIZE;
}
ind->nodes[ind->num_nodes ++] = current;

@ -25,6 +25,9 @@
# else
# define MXML_DEBUG(...)
# endif // DEBUG
# ifndef MXML_ALLOC_SIZE
# define MXML_ALLOC_SIZE 16 // Allocation increment
# endif // !MXML_ALLOC_SIZE
# define MXML_TAB 8 // Tabs every N columns

Loading…
Cancel
Save