more performance hunting reducing memory allocation and free and avoiding
* SAX2.c xmlreader.c include/libxml/parser.h: more performance hunting
reducing memory allocation and free and avoiding expensive routines
Daniel
diff --git a/xmlreader.c b/xmlreader.c
index eea9a28..eb8e6a2 100644
--- a/xmlreader.c
+++ b/xmlreader.c
@@ -263,9 +263,11 @@
(xmlDictOwns(reader->ctxt->dict, cur->name) != 1) &&
(cur->name != NULL))
xmlFree((xmlChar *)cur->name);
- if ((reader != NULL) && (reader->ctxt != NULL)) {
+ if ((reader != NULL) && (reader->ctxt != NULL) &&
+ (reader->ctxt->freeAttrsNr < 100)) {
cur->next = reader->ctxt->freeAttrs;
reader->ctxt->freeAttrs = cur;
+ reader->ctxt->freeAttrsNr++;
} else {
xmlFree(cur);
}
@@ -347,10 +349,13 @@
(cur->type != XML_COMMENT_NODE) &&
(cur->name != NULL))
xmlFree((xmlChar *)cur->name);
- if ((cur->type == XML_ELEMENT_NODE) &&
- (reader != NULL) && (reader->ctxt != NULL)) {
+ if (((cur->type == XML_ELEMENT_NODE) ||
+ (cur->type == XML_TEXT_NODE)) &&
+ (reader != NULL) && (reader->ctxt != NULL) &&
+ (reader->ctxt->freeElemsNr < 100)) {
cur->next = reader->ctxt->freeElems;
reader->ctxt->freeElems = cur;
+ reader->ctxt->freeElemsNr++;
} else {
xmlFree(cur);
}
@@ -414,10 +419,13 @@
(cur->type != XML_COMMENT_NODE) &&
(cur->name != NULL))
xmlFree((xmlChar *)cur->name);
- if ((cur->type == XML_ELEMENT_NODE) &&
- (reader != NULL) && (reader->ctxt != NULL)) {
+ if (((cur->type == XML_ELEMENT_NODE) ||
+ (cur->type == XML_TEXT_NODE)) &&
+ (reader != NULL) && (reader->ctxt != NULL) &&
+ (reader->ctxt->freeElemsNr < 100)) {
cur->next = reader->ctxt->freeElems;
reader->ctxt->freeElems = cur;
+ reader->ctxt->freeElemsNr++;
} else {
xmlFree(cur);
}