Commit c8c7be4b authored by Daniel Veillard's avatar Daniel Veillard
Browse files

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
parent 3bf65bea
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
......
......@@ -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;
/* 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);
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 {
if (ctxt->node_seq.length + 1 > ctxt->node_seq.maximum) {
xmlParserNodeInfo *tmp_buffer;
unsigned int byte_size;
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 ( 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;
}
/* If position is not at end, move elements out of the way */
if (pos != ctxt->node_seq.length) {
unsigned long i;
/* 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];
}
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++;
}
}
/************************************************************************
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment