diff --git a/extensions/transformiix/source/xpath/NodeSet.cpp b/extensions/transformiix/source/xpath/NodeSet.cpp
index fa09068e516b..60021ae04e5c 100644
--- a/extensions/transformiix/source/xpath/NodeSet.cpp
+++ b/extensions/transformiix/source/xpath/NodeSet.cpp
@@ -27,7 +27,7 @@
* Olivier Gerardin, ogerardin@vo.lu
* -- fixed numberValue()
*
- * $Id: NodeSet.cpp,v 1.5 2001/01/19 21:24:41 axel%pike.org Exp $
+ * $Id: NodeSet.cpp,v 1.6 2001/02/15 09:21:00 axel%pike.org Exp $
*/
#include "NodeSet.h"
@@ -40,7 +40,7 @@
* NodeSet
* This class was ported from XSL:P.
* @author Keith Visco
- * @version $Revision: 1.5 $ $Date: 2001/01/19 21:24:41 $
+ * @version $Revision: 1.6 $ $Date: 2001/02/15 09:21:00 $
**/
@@ -81,6 +81,7 @@ NodeSet::NodeSet(const NodeSet& source) {
* Helper method for Constructors
**/
void NodeSet::initialize(int size) {
+ checkDuplicates = MB_TRUE;
elements = new Node*[size];
for ( int i = 0; i < size; i++ ) elements[i] = 0;
elementCount = 0;
@@ -102,7 +103,9 @@ NodeSet::~NodeSet() {
* @return true if the Node is added to the NodeSet
**/
MBool NodeSet::add(Node* node) {
- if (node && !contains(node)) {
+
+ if (node) {
+ if (checkDuplicates && contains(node)) return MB_FALSE;
if (elementCount == bufferSize) increaseSize();
elements[elementCount++] = node;
return MB_TRUE;
@@ -121,7 +124,7 @@ MBool NodeSet::add(int index, Node* node)
{
if (!node || (index < 0) || (index > elementCount)) return MB_FALSE;
- if (contains(node)) return MB_FALSE;
+ if (checkDuplicates && contains(node)) return MB_FALSE;
// make sure we have room to add the object
if (elementCount == bufferSize) increaseSize();
@@ -193,6 +196,15 @@ Node* NodeSet::get(int index) {
return elements[index];
} //-- get
+/**
+ * Returns true if duplicate checking is enabled, otherwise false.
+ *
+ * @return true if duplicate checking is enabled, otherwise false.
+**/
+MBool NodeSet::getDuplicateChecking() {
+ return checkDuplicates;
+} //-- getDuplicateChecking
+
/**
* Returns the index of the specified Node,
* or -1 if the Node is not contained in the NodeSet
@@ -244,6 +256,18 @@ MBool NodeSet::remove(Node* node) {
} //-- remove
+/**
+ * Enables or disables checking for duplicates. By default
+ * the #add method will check for duplicate nodes. This should
+ * only be disabled when no possibility of duplicates could occur.
+ *
+ * @param checkDuplicates an MBool indicating, when true, to perform duplicate checking,
+ * otherwise duplicate checking is disabled.
+**/
+void NodeSet::setDuplicateChecking(MBool checkDuplicates) {
+ this->checkDuplicates = checkDuplicates;
+} //-- setDuplicateChecking
+
/**
* Returns the number of elements in the NodeSet
* @return the number of elements in the NodeSet
diff --git a/extensions/transformiix/source/xpath/NodeSet.h b/extensions/transformiix/source/xpath/NodeSet.h
index 706c3b595c40..4167d42d8497 100644
--- a/extensions/transformiix/source/xpath/NodeSet.h
+++ b/extensions/transformiix/source/xpath/NodeSet.h
@@ -24,13 +24,13 @@
* Larry Fitzpatrick, OpenText, lef@opentext.com
* -- moved initialization of DEFAULT_SIZE to NodeSet.cpp
*
- * $Id: NodeSet.h,v 1.5 2001/01/19 21:24:41 axel%pike.org Exp $
+ * $Id: NodeSet.h,v 1.6 2001/02/15 09:21:01 axel%pike.org Exp $
*/
/**
* NodeSet
* @author Keith Visco
- * @version $Revision: 1.5 $ $Date: 2001/01/19 21:24:41 $
+ * @version $Revision: 1.6 $ $Date: 2001/02/15 09:21:01 $
**/
#ifndef TRANSFRMX_NODESET_H
@@ -123,6 +123,12 @@ public:
**/
Node* get(int index);
+ /**
+ * Returns true if duplicate checking is enabled, otherwise false.
+ *
+ * @return true if duplicate checking is enabled, otherwise false.
+ **/
+ MBool getDuplicateChecking();
/**
* Returns the index of the specified Node,
@@ -152,6 +158,16 @@ public:
MBool remove(Node* node);
+ /**
+ * Enables or disables checking for duplicates. By default
+ * the #add method will check for duplicate nodes. This should
+ * only be disabled when no possibility of duplicates could occur.
+ *
+ * @param checkDuplicates an MBool indicating, when true, to perform duplicate checking,
+ * otherwise duplicate checking is disabled.
+ **/
+ void setDuplicateChecking(MBool checkDuplicates);
+
/**
* Returns the number of elements in the NodeSet
* @return the number of elements in the NodeSet
@@ -206,6 +222,8 @@ private:
int initialSize;
int bufferSize;
+ MBool checkDuplicates;
+
/**
* The next available location in the elements array
**/
diff --git a/extensions/transformiix/source/xslt/ProcessorState.cpp b/extensions/transformiix/source/xslt/ProcessorState.cpp
index d7528b4f4647..1ccec2af42eb 100644
--- a/extensions/transformiix/source/xslt/ProcessorState.cpp
+++ b/extensions/transformiix/source/xslt/ProcessorState.cpp
@@ -25,13 +25,13 @@
* -- added code in ::resolveFunctionCall to support the
* document() function.
*
- * $Id: ProcessorState.cpp,v 1.18 2001/01/27 15:05:39 axel%pike.org Exp $
+ * $Id: ProcessorState.cpp,v 1.19 2001/02/15 09:21:03 axel%pike.org Exp $
*/
/**
* Implementation of ProcessorState
* Much of this code was ported from XSL:P
- * @version $Revision: 1.18 $ $Date: 2001/01/27 15:05:39 $
+ * @version $Revision: 1.19 $ $Date: 2001/02/15 09:21:03 $
**/
#include "ProcessorState.h"
@@ -69,6 +69,7 @@ ProcessorState::ProcessorState(Document& xslDocument, Document& resultDocument)
* Destroys this ProcessorState
**/
ProcessorState::~ProcessorState() {
+
if (dfWildCardTemplate)
delete dfWildCardTemplate;
if (dfTextTemplate)
@@ -839,28 +840,34 @@ void ProcessorState::sortByDocumentOrder(NodeSet* nodes) {
if ((!nodes) || (nodes->size() < 2)) return;
NodeSet sorted(nodes->size());
+ sorted.setDuplicateChecking(MB_FALSE);
sorted.add(nodes->get(0));
int i = 1;
for ( ; i < nodes->size(); i++) {
Node* node = nodes->get(i);
- for (int k = 0; k < sorted.size(); k++) {
+ for (int k = i-1; k >= 0; k--) {
Node* tmpNode = sorted.get(k);
- if (domHelper.appearsFirst(node, tmpNode) == node) {
- sorted.add(k, node);
+ if (domHelper.appearsFirst(node, tmpNode) == tmpNode) {
+ if (k == i-1) sorted.add(node);
+ else sorted.add(k, node);
break;
}
- else if (k == sorted.size()-1) {
- sorted.add(node);
+ else if (k == 0) {
+ sorted.add(0, node);
break;
}
}
}
+ //-- save current state of duplicates checking
+ MBool checkDuplicates = nodes->getDuplicateChecking();
+ nodes->setDuplicateChecking(MB_FALSE);
nodes->clear();
- for (i = 0; i < sorted.size(); i++)
+ for (i = 0; i < sorted.size(); i++) {
nodes->add(sorted.get(i));
-
+ }
+ nodes->setDuplicateChecking(checkDuplicates);
sorted.clear();
} //-- sortByDocumentOrder