1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2024-10-26 12:25:09 +03:00

Greg Sjaardema suggested to use an eponential buffer groth policy in

* parserInternals.h: Greg Sjaardema suggested to use an
  eponential buffer groth policy in xmlParserAddNodeInfo()
Daniel
This commit is contained in:
Daniel Veillard 2002-01-23 17:53:44 +00:00
parent 3bf65bea7d
commit c8c7be4b17
2 changed files with 51 additions and 42 deletions

View File

@ -1,3 +1,8 @@
Wed Jan 23 15:14:22 CET 2002 Daniel Veillard <daniel@veillard.com>
* parserInternals.h: Greg Sjaardema suggested to use an
eponential buffer groth policy in xmlParserAddNodeInfo()
Wed Jan 23 13:32:40 CET 2002 Daniel Veillard <daniel@veillard.com>
* doc/api.xsl doc/APIconstructors.html doc/APIfiles.html

View File

@ -2469,55 +2469,59 @@ unsigned long xmlParserFindNodeInfoIndex(const xmlParserNodeInfoSeqPtr seq,
* Insert node info record into the sorted sequence
*/
void
xmlParserAddNodeInfo(xmlParserCtxtPtr ctxt,
xmlParserAddNodeInfo(xmlParserCtxtPtr ctxt,
const xmlParserNodeInfoPtr info)
{
unsigned long pos;
static unsigned int block_size = 5;
unsigned long pos;
/* Find pos and check to see if node is already in the sequence */
pos = xmlParserFindNodeInfoIndex(&ctxt->node_seq, (const xmlNodePtr)
info->node);
if ( pos < ctxt->node_seq.length
&& ctxt->node_seq.buffer[pos].node == info->node ) {
ctxt->node_seq.buffer[pos] = *info;
}
/* Otherwise, we need to add new node to buffer */
else {
/* Expand buffer by 5 if needed */
if ( ctxt->node_seq.length + 1 > ctxt->node_seq.maximum ) {
xmlParserNodeInfo* tmp_buffer;
unsigned int byte_size = (sizeof(*ctxt->node_seq.buffer)
*(ctxt->node_seq.maximum + block_size));
if ( ctxt->node_seq.buffer == NULL )
tmp_buffer = (xmlParserNodeInfo*) xmlMalloc(byte_size);
else
tmp_buffer = (xmlParserNodeInfo*) xmlRealloc(ctxt->node_seq.buffer, byte_size);
if ( tmp_buffer == NULL ) {
if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
ctxt->sax->error(ctxt->userData, "Out of memory\n");
ctxt->errNo = XML_ERR_NO_MEMORY;
return;
}
ctxt->node_seq.buffer = tmp_buffer;
ctxt->node_seq.maximum += block_size;
/* Find pos and check to see if node is already in the sequence */
pos = xmlParserFindNodeInfoIndex(&ctxt->node_seq, (const xmlNodePtr)
info->node);
if (pos < ctxt->node_seq.length
&& ctxt->node_seq.buffer[pos].node == info->node) {
ctxt->node_seq.buffer[pos] = *info;
}
/* If position is not at end, move elements out of the way */
if ( pos != ctxt->node_seq.length ) {
unsigned long i;
/* Otherwise, we need to add new node to buffer */
else {
if (ctxt->node_seq.length + 1 > ctxt->node_seq.maximum) {
xmlParserNodeInfo *tmp_buffer;
unsigned int byte_size;
for ( i = ctxt->node_seq.length; i > pos; i-- )
ctxt->node_seq.buffer[i] = ctxt->node_seq.buffer[i - 1];
if (ctxt->node_seq.maximum == 0)
ctxt->node_seq.maximum = 2;
byte_size = (sizeof(*ctxt->node_seq.buffer) *
(2 * ctxt->node_seq.maximum));
if (ctxt->node_seq.buffer == NULL)
tmp_buffer = (xmlParserNodeInfo *) xmlMalloc(byte_size);
else
tmp_buffer =
(xmlParserNodeInfo *) xmlRealloc(ctxt->node_seq.buffer,
byte_size);
if (tmp_buffer == NULL) {
if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
ctxt->sax->error(ctxt->userData, "Out of memory\n");
ctxt->errNo = XML_ERR_NO_MEMORY;
return;
}
ctxt->node_seq.buffer = tmp_buffer;
ctxt->node_seq.maximum *= 2;
}
/* If position is not at end, move elements out of the way */
if (pos != ctxt->node_seq.length) {
unsigned long i;
for (i = ctxt->node_seq.length; i > pos; i--)
ctxt->node_seq.buffer[i] = ctxt->node_seq.buffer[i - 1];
}
/* Copy element and increase length */
ctxt->node_seq.buffer[pos] = *info;
ctxt->node_seq.length++;
}
/* Copy element and increase length */
ctxt->node_seq.buffer[pos] = *info;
ctxt->node_seq.length++;
}
}
/************************************************************************