applied optimization patch from Petr Pajas Daniel

* xpath.c: applied optimization patch from Petr Pajas
Daniel
diff --git a/ChangeLog b/ChangeLog
index 28ddc7f..e5dbbcc 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+Tue Feb 17 12:47:20 CET 2004 Daniel Veillard <daniel@veillard.com>
+
+	* xpath.c: applied optimization patch from Petr Pajas
+
 Tue Feb 17 12:39:08 CET 2004 Daniel Veillard <daniel@veillard.com>
 
 	* xmlwriter.c include/libxml/xmlwriter.h: applied update
diff --git a/xpath.c b/xpath.c
index 0986986..3f3e436 100644
--- a/xpath.c
+++ b/xpath.c
@@ -1616,8 +1616,28 @@
     /*
      * Find who's first.
      */
+    if (node1 == node2->prev)
+	return(1);
     if (node1 == node2->next)
 	return(-1);
+    /*
+     * Speedup using document order if availble.
+     */
+    if ((node1->type == XML_ELEMENT_NODE) &&
+	(node2->type == XML_ELEMENT_NODE) &&
+	(0 > (long) node1->content) &&
+	(0 > (long) node2->content) &&
+	(node1->doc == node2->doc)) {
+	long l1, l2;
+
+	l1 = -((long) node1->content);
+	l2 = -((long) node2->content);
+	if (l1 < l2)
+	    return(1);
+	if (l1 > l2)
+	    return(-1);
+    }
+
     for (cur = node1->next;cur != NULL;cur = cur->next)
 	if (cur == node2)
 	    return(1);