1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2025-07-30 22:43:14 +03:00

first part of the fix to performance bug #108905, adds

* xpath.c include/libxml/xpath.h: first part of the fix to
  performance bug #108905, adds xmlXPathOrderDocElems() providing
  document order for nodes.
* python/libxml.c: Python may require TRIO as Albert Chin pointed out
Daniel
This commit is contained in:
Daniel Veillard
2003-03-26 00:38:10 +00:00
parent 09628210bd
commit e4fa293265
4 changed files with 70 additions and 10 deletions

View File

@ -1,3 +1,10 @@
Wed Mar 26 01:34:19 CET 2003 Daniel Veillard <daniel@veillard.com>
* xpath.c include/libxml/xpath.h: first part of the fix to
performance bug #108905, adds xmlXPathOrderDocElems() providing
document order for nodes.
* python/libxml.c: Python may require TRIO as Albert Chin pointed out
Tue Mar 25 16:07:00 CET 2003 Daniel Veillard <daniel@veillard.com> Tue Mar 25 16:07:00 CET 2003 Daniel Veillard <daniel@veillard.com>
* xmlschemastypes.c: removing a warning with Sun compiler * xmlschemastypes.c: removing a warning with Sun compiler

View File

@ -391,6 +391,7 @@ void xmlXPathFreeContext (xmlXPathContextPtr ctxt);
/** /**
* Evaluation functions. * Evaluation functions.
*/ */
long xmlXPathOrderDocElems (xmlDocPtr doc);
xmlXPathObjectPtr xmlXPathEval (const xmlChar *str, xmlXPathObjectPtr xmlXPathEval (const xmlChar *str,
xmlXPathContextPtr ctx); xmlXPathContextPtr ctx);
xmlXPathObjectPtr xmlXPathEvalExpression (const xmlChar *str, xmlXPathObjectPtr xmlXPathEvalExpression (const xmlChar *str,

View File

@ -27,6 +27,9 @@
#if (defined(_MSC_VER) || defined(__MINGW32__)) && !defined(vsnprintf) #if (defined(_MSC_VER) || defined(__MINGW32__)) && !defined(vsnprintf)
#define vsnprintf(b,c,f,a) _vsnprintf(b,c,f,a) #define vsnprintf(b,c,f,a) _vsnprintf(b,c,f,a)
#elif defined(WITH_TRIO)
#include "trio.h"
#define vsnprintf trio_vsnprintf
#endif #endif
/* #define DEBUG */ /* #define DEBUG */

69
xpath.c
View File

@ -1339,6 +1339,56 @@ xmlXPatherror(xmlXPathParserContextPtr ctxt, const char *file ATTRIBUTE_UNUSED,
* * * *
************************************************************************/ ************************************************************************/
/**
* xmlXPathOrderDocElems:
* @doc: an input document
*
* Call this routine to speed up XPath computation on static documents.
* This stamps all the element nodes with the document order
* Like for line information, the order is kept in the element->content
* field, the value stored is actually - the node number (startting at -1)
* to be able to differenciate from line numbers.
*
* Returns the number of element found in the document or -1 in case
* of error.
*/
long
xmlXPathOrderDocElems(xmlDocPtr doc) {
long count = 0;
xmlNodePtr cur;
if (doc == NULL)
return(-1);
cur = doc->children;
while (cur != NULL) {
if (cur->type == XML_ELEMENT_NODE) {
cur->content = (void *) (-(++count));
if (cur->children != NULL) {
cur = cur->children;
continue;
}
}
if (cur->next != NULL) {
cur = cur->next;
continue;
}
do {
cur = cur->parent;
if (cur == NULL)
break;
if (cur == (xmlNodePtr) doc) {
cur = NULL;
break;
}
if (cur->next != NULL) {
cur = cur->next;
break;
}
} while (cur != NULL);
}
return(count);
}
/** /**
* xmlXPathCmpNodes: * xmlXPathCmpNodes:
* @node1: the first node * @node1: the first node
@ -1383,25 +1433,24 @@ xmlXPathCmpNodes(xmlNodePtr node1, xmlNodePtr node2) {
if (node1 == node2->next) if (node1 == node2->next)
return(-1); return(-1);
#if 0
Unfortunately this does not work. Line number in entities reset
to 1 within the entity :-(
/* /*
* Speedup using line numbers if availble. * Speedup using document order if availble.
*/ */
if ((node1->type == XML_ELEMENT_NODE) && if ((node1->type == XML_ELEMENT_NODE) &&
(node2->type == XML_ELEMENT_NODE) && (node2->type == XML_ELEMENT_NODE) &&
(0 != (int) node1->content) && (0 != (int) node2->content)) { (0 > (long) node1->content) &&
int l1, l2; (0 > (long) node2->content) &&
l1 = (int) node1->content; (node1->doc == node2->doc)) {
l2 = (int) node2->content; long l1, l2;
l1 = -((long) node1->content);
l2 = -((long) node2->content);
if (l1 < l2) if (l1 < l2)
return(1); return(1);
if (l1 > l2) if (l1 > l2)
return(-1); return(-1);
} }
#endif
/* /*
* compute depth to root * compute depth to root
*/ */