1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2025-07-29 11:41:22 +03:00

optimization when freeing hash tables. some tuning of buffer allocations

* dict.c hash.c: optimization when freeing hash tables.
* parser.c xmlIO.c include/libxml/tree.h: some tuning of buffer
  allocations
* parser.c parserInternals.c include/libxml/parser.h: keep a
  single allocated block for all the attributes callbacks,
  avoid useless malloc()/free()
* tree.c: do not realloc() when growing a buffer if the buffer
  ain't full, malloc/memcpy/free avoid copying memory.
Daniel
This commit is contained in:
Daniel Veillard
2003-08-19 15:01:28 +00:00
parent 66f68e716b
commit 6155d8aafa
9 changed files with 60 additions and 21 deletions

14
tree.c
View File

@ -6413,9 +6413,21 @@ xmlBufferResize(xmlBufferPtr buf, unsigned int size)
if (buf->content == NULL)
rebuf = (xmlChar *) xmlMallocAtomic(newSize * sizeof(xmlChar));
else
else if (buf->size - buf->use < 100) {
rebuf = (xmlChar *) xmlRealloc(buf->content,
newSize * sizeof(xmlChar));
} else {
/*
* if we are reallocating a buffer far from being full, it's
* better to make a new allocation and copy only the used range
* and free the old one.
*/
rebuf = (xmlChar *) xmlMallocAtomic(newSize * sizeof(xmlChar));
if (rebuf != NULL) {
memcpy(rebuf, buf->content, buf->use);
xmlFree(buf->content);
}
}
if (rebuf == NULL) {
xmlGenericError(xmlGenericErrorContext,
"xmlBufferResize : out of memory!\n");