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

34
tree.c
View File

@ -490,15 +490,30 @@ xmlFreeDoc(xmlDocPtr cur) {
#endif
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->name != NULL) xmlFree((char *) cur->name);
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->ids != NULL) xmlFreeIDTable((xmlIDTablePtr) cur->ids);
if (cur->refs != NULL) xmlFreeRefTable((xmlRefTablePtr) cur->refs);
if (cur->URL != NULL) xmlFree((char *) cur->URL);
xmlFree(cur);
}
@ -1178,9 +1193,12 @@ xmlFreeProp(xmlAttrPtr cur) {
return;
}
/* Check for ID removal -> leading to invalid references ! */
if ((cur->parent != NULL) &&
(xmlIsID(cur->parent->doc, cur->parent, cur)))
xmlRemoveID(cur->parent->doc, cur);
if ((cur->parent != NULL) && (cur->parent->doc != NULL) &&
((cur->parent->doc->intSubset != NULL) ||
(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->children != NULL) xmlFreeNodeList(cur->children);
xmlFree(cur);

13
xpath.c
View File

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