You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xalan.apache.org by db...@locus.apache.org on 2000/05/30 00:22:10 UTC

cvs commit: xml-xalan/c/src/XPath MutableNodeRefList.cpp NodeRefList.cpp NodeRefList.hpp

dbertoni    00/05/29 15:22:10

  Modified:    c/src/XPath MutableNodeRefList.cpp NodeRefList.cpp
                        NodeRefList.hpp
  Log:
  Added debugging code to check for duplicate nodes.  Added some code to prevent some reallocations, and to prevent duplicates from being added.
  
  Revision  Changes    Path
  1.9       +24 -7     xml-xalan/c/src/XPath/MutableNodeRefList.cpp
  
  Index: MutableNodeRefList.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/XPath/MutableNodeRefList.cpp,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- MutableNodeRefList.cpp	2000/05/05 15:12:17	1.8
  +++ MutableNodeRefList.cpp	2000/05/29 22:22:09	1.9
  @@ -258,6 +258,12 @@
   {
   	const unsigned int	theLength = nodelist.getLength();
   
  +	// Reserve the space at the start.  We may end up reserving
  +	// more space than necessary, but it's a small price to
  +	// pay for the increased speed.  We can always shrink by
  +	// swapping if we have way to much space.
  +	m_nodeList.reserve(getLength() + theLength);
  +
   	for (unsigned int i = 0; i < theLength; i++)
   	{
   		addNode(nodelist.item(i));
  @@ -269,11 +275,17 @@
   void
   MutableNodeRefList::addNodesInDocOrder(const XalanNodeList&		nodelist)
   {
  -	const unsigned int	nChildren = nodelist.getLength();
  +	const unsigned int	theLength = nodelist.getLength();
  +
  +	// Reserve the space at the start.  We may end up reserving
  +	// more space than necessary, but it's a small price to
  +	// pay for the increased speed.  We can always shrink by
  +	// swapping if we have way to much space.
  +	m_nodeList.reserve(getLength() + theLength);
   
  -	for(unsigned int i = 0; i < nChildren; i++)
  +	for(unsigned int i = 0; i < theLength; i++)
   	{
  -		addNodeInDocOrder(nodelist.item(i), false);
  +		addNodeInDocOrder(nodelist.item(i), true);
   	}
   }
   
  @@ -282,9 +294,15 @@
   void
   MutableNodeRefList::addNodesInDocOrder(const NodeRefListBase&	nodelist)
   {
  -	const unsigned int	nChildren = nodelist.getLength();
  +	const unsigned int	theLength = nodelist.getLength();
   
  -	for(unsigned int i = 0; i < nChildren; i++)
  +	// Reserve the space at the start.  We may end up reserving
  +	// more space than necessary, but it's a small price to
  +	// pay for the increased speed.  We can always shrink by
  +	// swapping if we have way to much space.
  +	m_nodeList.reserve(getLength() + theLength);
  +
  +	for(unsigned int i = 0; i < theLength; i++)
   	{
   		addNodeInDocOrder(nodelist.item(i), true);
   	}
  @@ -305,9 +323,8 @@
   		{
   			addNode(node);
   		}
  -		else
  +		else if (indexOf(node) == npos)
   		{
  -
   			unsigned int	i = size - 1;
   
   			// When wrap-around happens, i will be > than size...
  
  
  
  1.6       +41 -0     xml-xalan/c/src/XPath/NodeRefList.cpp
  
  Index: NodeRefList.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/XPath/NodeRefList.cpp,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- NodeRefList.cpp	2000/04/11 14:46:09	1.5
  +++ NodeRefList.cpp	2000/05/29 22:22:09	1.6
  @@ -62,6 +62,10 @@
   #include <cassert>
   #include <algorithm>
   
  +#if !defined(NDEBUG)
  +#include <set>
  +#endif
  +
   
   
   NodeRefList::NodeRefList() :
  @@ -184,3 +188,40 @@
   {
   	return 0;
   }
  +
  +
  +
  +#if !defined(NDEBUG)
  +bool
  +NodeRefList::checkForDuplicates() const
  +{
  +#if !defined(XALAN_NO_NAMESPACES)
  +	using std::set;
  +#endif
  +
  +	bool	fResult = false;
  +
  +	const unsigned int	theLength = getLength();
  +
  +	if (theLength > 0)
  +	{
  +		set<const XalanNode*>	theNodes;
  +
  +		for (unsigned i = 0; i < theLength && fResult == false; ++i)
  +		{
  +			const XalanNode* const	theNode = item(i);
  +
  +			if (theNodes.find(theNode) != theNodes.end())
  +			{
  +				fResult = true;
  +			}
  +			else
  +			{
  +				theNodes.insert(theNode);
  +			}
  +		}
  +	}
  +
  +	return fResult;
  +}
  +#endif
  
  
  
  1.7       +5 -0      xml-xalan/c/src/XPath/NodeRefList.hpp
  
  Index: NodeRefList.hpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/XPath/NodeRefList.hpp,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- NodeRefList.hpp	2000/04/11 14:46:09	1.6
  +++ NodeRefList.hpp	2000/05/29 22:22:09	1.7
  @@ -121,6 +121,11 @@
   	virtual XPathSupport*
   	getSupport() const;
   
  +#if !defined(NDEBUG)
  +	bool
  +	checkForDuplicates() const;
  +#endif
  +
   protected:
   
   #if defined(XALAN_NO_NAMESPACES)