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
diff --git a/parserInternals.c b/parserInternals.c
index 031f3c1..b8bdaa9 100644
--- a/parserInternals.c
+++ b/parserInternals.c
@@ -2469,55 +2469,59 @@
* 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++;
- }
}
/************************************************************************