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

- xpath.c tree.c parser.c: speed optimizations at the parser level

document tree freeing and xpath evaluation
Daniel
This commit is contained in:
Daniel Veillard
2001-05-16 21:05:17 +00:00
parent fd7ddca8b2
commit 76d66f416d
4 changed files with 57 additions and 29 deletions

View File

@ -1,3 +1,8 @@
Wed May 16 23:02:41 CEST 2001 Daniel Veillard <Daniel.Veillard@imag.fr>
* xpath.c tree.c parser.c: speed optimizations at the parser level
document tree freeing and xpath evaluation
Wed May 16 12:55:48 CEST 2001 Daniel Veillard <Daniel.Veillard@imag.fr> Wed May 16 12:55:48 CEST 2001 Daniel Veillard <Daniel.Veillard@imag.fr>
* parser.c parser.h parserInternals.h: fixed a couple of * parser.c parser.h parserInternals.h: fixed a couple of

View File

@ -1627,7 +1627,7 @@ xmlSplitQName(xmlParserCtxtPtr ctxt, const xmlChar *name, xmlChar **prefix) {
* * * *
************************************************************************/ ************************************************************************/
xmlChar *xmlParseNameComplex(xmlParserCtxtPtr ctxt); static xmlChar * xmlParseNameComplex(xmlParserCtxtPtr ctxt);
/** /**
* xmlParseName: * xmlParseName:
* @ctxt: an XML parser context * @ctxt: an XML parser context
@ -1663,9 +1663,10 @@ xmlParseName(xmlParserCtxtPtr ctxt) {
while (((*in >= 0x61) && (*in <= 0x7A)) || while (((*in >= 0x61) && (*in <= 0x7A)) ||
((*in >= 0x41) && (*in <= 0x5A)) || ((*in >= 0x41) && (*in <= 0x5A)) ||
((*in >= 0x30) && (*in <= 0x39)) || ((*in >= 0x30) && (*in <= 0x39)) ||
(*in == '_') || (*in == ':')) (*in == '_') || (*in == '-') ||
(*in == ':') || (*in == '.'))
in++; in++;
if ((*in == ' ') || (*in == '>') || (*in == '/')) { if ((*in > 0) && (*in < 0x80)) {
count = in - ctxt->input->cur; count = in - ctxt->input->cur;
ret = xmlStrndup(ctxt->input->cur, count); ret = xmlStrndup(ctxt->input->cur, count);
ctxt->input->cur = in; ctxt->input->cur = in;
@ -1675,7 +1676,7 @@ xmlParseName(xmlParserCtxtPtr ctxt) {
return(xmlParseNameComplex(ctxt)); return(xmlParseNameComplex(ctxt));
} }
xmlChar * static xmlChar *
xmlParseNameComplex(xmlParserCtxtPtr ctxt) { xmlParseNameComplex(xmlParserCtxtPtr ctxt) {
xmlChar buf[XML_MAX_NAMELEN + 5]; xmlChar buf[XML_MAX_NAMELEN + 5];
int len = 0, l; int len = 0, l;
@ -3071,7 +3072,7 @@ xmlParseNotationDecl(xmlParserCtxtPtr ctxt) {
} }
SKIP_BLANKS; SKIP_BLANKS;
name = xmlParseNameComplex(ctxt); name = xmlParseName(ctxt);
if (name == NULL) { if (name == NULL) {
ctxt->errNo = XML_ERR_NOTATION_NOT_STARTED; ctxt->errNo = XML_ERR_NOTATION_NOT_STARTED;
if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
@ -3189,7 +3190,7 @@ xmlParseEntityDecl(xmlParserCtxtPtr ctxt) {
isParameter = 1; isParameter = 1;
} }
name = xmlParseNameComplex(ctxt); name = xmlParseName(ctxt);
if (name == NULL) { if (name == NULL) {
ctxt->errNo = XML_ERR_NAME_REQUIRED; ctxt->errNo = XML_ERR_NAME_REQUIRED;
if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
@ -3329,7 +3330,7 @@ xmlParseEntityDecl(xmlParserCtxtPtr ctxt) {
ctxt->disableSAX = 1; ctxt->disableSAX = 1;
} }
SKIP_BLANKS; SKIP_BLANKS;
ndata = xmlParseNameComplex(ctxt); ndata = xmlParseName(ctxt);
if ((ctxt->sax != NULL) && (!ctxt->disableSAX) && if ((ctxt->sax != NULL) && (!ctxt->disableSAX) &&
(ctxt->sax->unparsedEntityDecl != NULL)) (ctxt->sax->unparsedEntityDecl != NULL))
ctxt->sax->unparsedEntityDecl(ctxt->userData, name, ctxt->sax->unparsedEntityDecl(ctxt->userData, name,
@ -3507,7 +3508,7 @@ xmlParseNotationType(xmlParserCtxtPtr ctxt) {
do { do {
NEXT; NEXT;
SKIP_BLANKS; SKIP_BLANKS;
name = xmlParseNameComplex(ctxt); name = xmlParseName(ctxt);
if (name == NULL) { if (name == NULL) {
ctxt->errNo = XML_ERR_NAME_REQUIRED; ctxt->errNo = XML_ERR_NAME_REQUIRED;
if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
@ -3776,7 +3777,7 @@ xmlParseAttributeListDecl(xmlParserCtxtPtr ctxt) {
ctxt->disableSAX = 1; ctxt->disableSAX = 1;
} }
SKIP_BLANKS; SKIP_BLANKS;
elemName = xmlParseNameComplex(ctxt); elemName = xmlParseName(ctxt);
if (elemName == NULL) { if (elemName == NULL) {
ctxt->errNo = XML_ERR_NAME_REQUIRED; ctxt->errNo = XML_ERR_NAME_REQUIRED;
if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
@ -3796,7 +3797,7 @@ xmlParseAttributeListDecl(xmlParserCtxtPtr ctxt) {
GROW; GROW;
tree = NULL; tree = NULL;
attrName = xmlParseNameComplex(ctxt); attrName = xmlParseName(ctxt);
if (attrName == NULL) { if (attrName == NULL) {
ctxt->errNo = XML_ERR_NAME_REQUIRED; ctxt->errNo = XML_ERR_NAME_REQUIRED;
if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
@ -3985,7 +3986,7 @@ xmlParseElementMixedContentDecl(xmlParserCtxtPtr ctxt) {
xmlFree(elem); xmlFree(elem);
} }
SKIP_BLANKS; SKIP_BLANKS;
elem = xmlParseNameComplex(ctxt); elem = xmlParseName(ctxt);
if (elem == NULL) { if (elem == NULL) {
ctxt->errNo = XML_ERR_NAME_REQUIRED; ctxt->errNo = XML_ERR_NAME_REQUIRED;
if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
@ -4084,7 +4085,7 @@ xmlParseElementChildrenContentDecl
SKIP_BLANKS; SKIP_BLANKS;
GROW; GROW;
} else { } else {
elem = xmlParseNameComplex(ctxt); elem = xmlParseName(ctxt);
if (elem == NULL) { if (elem == NULL) {
ctxt->errNo = XML_ERR_ELEMCONTENT_NOT_STARTED; ctxt->errNo = XML_ERR_ELEMCONTENT_NOT_STARTED;
if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
@ -4239,7 +4240,7 @@ xmlParseElementChildrenContentDecl
last = xmlParseElementChildrenContentDecl(ctxt); last = xmlParseElementChildrenContentDecl(ctxt);
SKIP_BLANKS; SKIP_BLANKS;
} else { } else {
elem = xmlParseNameComplex(ctxt); elem = xmlParseName(ctxt);
if (elem == NULL) { if (elem == NULL) {
ctxt->errNo = XML_ERR_ELEMCONTENT_NOT_STARTED; ctxt->errNo = XML_ERR_ELEMCONTENT_NOT_STARTED;
if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
@ -4393,7 +4394,7 @@ xmlParseElementDecl(xmlParserCtxtPtr ctxt) {
ctxt->disableSAX = 1; ctxt->disableSAX = 1;
} }
SKIP_BLANKS; SKIP_BLANKS;
name = xmlParseNameComplex(ctxt); name = xmlParseName(ctxt);
if (name == NULL) { if (name == NULL) {
ctxt->errNo = XML_ERR_NAME_REQUIRED; ctxt->errNo = XML_ERR_NAME_REQUIRED;
if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
@ -5022,7 +5023,8 @@ xmlParseReference(xmlParserCtxtPtr ctxt) {
ctxt->wellFormed = 0; ctxt->wellFormed = 0;
ctxt->disableSAX = 1; ctxt->disableSAX = 1;
} else if ((ret == 0) && (list != NULL)) { } else if ((ret == 0) && (list != NULL)) {
if ((ent->etype == XML_INTERNAL_GENERAL_ENTITY) && if (((ent->etype == XML_INTERNAL_GENERAL_ENTITY) ||
(ent->etype == XML_EXTERNAL_GENERAL_PARSED_ENTITY))&&
(ent->children == NULL)) { (ent->children == NULL)) {
ent->children = list; ent->children = list;
while (list != NULL) { while (list != NULL) {
@ -5529,7 +5531,7 @@ xmlParsePEReference(xmlParserCtxtPtr ctxt) {
if (RAW == '%') { if (RAW == '%') {
NEXT; NEXT;
name = xmlParseNameComplex(ctxt); name = xmlParseName(ctxt);
if (name == NULL) { if (name == NULL) {
ctxt->errNo = XML_ERR_NAME_REQUIRED; ctxt->errNo = XML_ERR_NAME_REQUIRED;
if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))

34
tree.c
View File

@ -490,15 +490,30 @@ xmlFreeDoc(xmlDocPtr cur) {
#endif #endif
return; return;
} }
/*
* Do this before freeing the children list to avoid ID lookups
*/
if (cur->ids != NULL) xmlFreeIDTable((xmlIDTablePtr) cur->ids);
cur->ids = NULL;
if (cur->refs != NULL) xmlFreeRefTable((xmlRefTablePtr) cur->refs);
cur->refs = NULL;
if (cur->extSubset != NULL) {
xmlUnlinkNode((xmlNodePtr) cur->extSubset);
xmlFreeDtd(cur->extSubset);
cur->extSubset = NULL;
}
if (cur->intSubset != NULL) {
xmlUnlinkNode((xmlNodePtr) cur->intSubset);
xmlFreeDtd(cur->intSubset);
cur->intSubset = NULL;
}
if (cur->children != NULL) xmlFreeNodeList(cur->children);
if (cur->version != NULL) xmlFree((char *) cur->version); if (cur->version != NULL) xmlFree((char *) cur->version);
if (cur->name != NULL) xmlFree((char *) cur->name); if (cur->name != NULL) xmlFree((char *) cur->name);
if (cur->encoding != NULL) xmlFree((char *) cur->encoding); if (cur->encoding != NULL) xmlFree((char *) cur->encoding);
if (cur->children != NULL) xmlFreeNodeList(cur->children);
if (cur->intSubset != NULL) xmlFreeDtd(cur->intSubset);
if (cur->extSubset != NULL) xmlFreeDtd(cur->extSubset);
if (cur->oldNs != NULL) xmlFreeNsList(cur->oldNs); if (cur->oldNs != NULL) xmlFreeNsList(cur->oldNs);
if (cur->ids != NULL) xmlFreeIDTable((xmlIDTablePtr) cur->ids);
if (cur->refs != NULL) xmlFreeRefTable((xmlRefTablePtr) cur->refs);
if (cur->URL != NULL) xmlFree((char *) cur->URL); if (cur->URL != NULL) xmlFree((char *) cur->URL);
xmlFree(cur); xmlFree(cur);
} }
@ -1178,9 +1193,12 @@ xmlFreeProp(xmlAttrPtr cur) {
return; return;
} }
/* Check for ID removal -> leading to invalid references ! */ /* Check for ID removal -> leading to invalid references ! */
if ((cur->parent != NULL) && if ((cur->parent != NULL) && (cur->parent->doc != NULL) &&
(xmlIsID(cur->parent->doc, cur->parent, cur))) ((cur->parent->doc->intSubset != NULL) ||
xmlRemoveID(cur->parent->doc, cur); (cur->parent->doc->extSubset != NULL))) {
if (xmlIsID(cur->parent->doc, cur->parent, cur))
xmlRemoveID(cur->parent->doc, cur);
}
if (cur->name != NULL) xmlFree((char *) cur->name); if (cur->name != NULL) xmlFree((char *) cur->name);
if (cur->children != NULL) xmlFreeNodeList(cur->children); if (cur->children != NULL) xmlFreeNodeList(cur->children);
xmlFree(cur); xmlFree(cur);

13
xpath.c
View File

@ -1926,7 +1926,7 @@ xmlXPathRegisteredVariablesCleanup(xmlXPathContextPtr ctxt) {
if (ctxt == NULL) if (ctxt == NULL)
return; return;
xmlHashFree(ctxt->varHash, NULL); xmlHashFree(ctxt->varHash, (xmlHashDeallocator)xmlXPathFreeObject);
ctxt->varHash = NULL; ctxt->varHash = NULL;
} }
@ -5603,9 +5603,10 @@ xmlXPathParseName(xmlXPathParserContextPtr ctxt) {
while (((*in >= 0x61) && (*in <= 0x7A)) || while (((*in >= 0x61) && (*in <= 0x7A)) ||
((*in >= 0x41) && (*in <= 0x5A)) || ((*in >= 0x41) && (*in <= 0x5A)) ||
((*in >= 0x30) && (*in <= 0x39)) || ((*in >= 0x30) && (*in <= 0x39)) ||
(*in == '_') || (*in == ':')) (*in == '_') || (*in == '-') ||
(*in == ':') || (*in == '.'))
in++; in++;
if ((*in == ' ') || (*in == '>') || (*in == '/')) { if ((*in > 0) && (*in < 0x80)) {
count = in - ctxt->cur; count = in - ctxt->cur;
ret = xmlStrndup(ctxt->cur, count); ret = xmlStrndup(ctxt->cur, count);
ctxt->cur = in; ctxt->cur = in;
@ -7452,7 +7453,7 @@ xmlXPathCompOpEval(xmlXPathParserContextPtr ctxt, xmlXPathStepOpPtr op) {
case XPATH_OP_AND: case XPATH_OP_AND:
xmlXPathCompOpEval(ctxt, &comp->steps[op->ch1]); xmlXPathCompOpEval(ctxt, &comp->steps[op->ch1]);
xmlXPathBooleanFunction(ctxt, 1); xmlXPathBooleanFunction(ctxt, 1);
if (ctxt->value->boolval == 0) if ((ctxt->value == NULL) || (ctxt->value->boolval == 0))
return; return;
arg2 = valuePop(ctxt); arg2 = valuePop(ctxt);
xmlXPathCompOpEval(ctxt, &comp->steps[op->ch2]); xmlXPathCompOpEval(ctxt, &comp->steps[op->ch2]);
@ -7465,7 +7466,7 @@ xmlXPathCompOpEval(xmlXPathParserContextPtr ctxt, xmlXPathStepOpPtr op) {
case XPATH_OP_OR: case XPATH_OP_OR:
xmlXPathCompOpEval(ctxt, &comp->steps[op->ch1]); xmlXPathCompOpEval(ctxt, &comp->steps[op->ch1]);
xmlXPathBooleanFunction(ctxt, 1); xmlXPathBooleanFunction(ctxt, 1);
if (ctxt->value->boolval == 1) if ((ctxt->value == NULL) || (ctxt->value->boolval == 1))
return; return;
arg2 = valuePop(ctxt); arg2 = valuePop(ctxt);
xmlXPathCompOpEval(ctxt, &comp->steps[op->ch2]); xmlXPathCompOpEval(ctxt, &comp->steps[op->ch2]);
@ -7624,6 +7625,8 @@ xmlXPathCompOpEval(xmlXPathParserContextPtr ctxt, xmlXPathStepOpPtr op) {
xmlXPathCompOpEval(ctxt, &comp->steps[op->ch1]); xmlXPathCompOpEval(ctxt, &comp->steps[op->ch1]);
if (op->ch2 == -1) if (op->ch2 == -1)
return; return;
if (ctxt->value == NULL)
return;
oldnode = ctxt->context->node; oldnode = ctxt->context->node;