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...@apache.org on 2003/07/10 01:44:13 UTC

cvs commit: xml-xalan/c/src/xalanc/XSLT ElemForEach.cpp ElemSort.cpp NodeSorter.cpp NodeSorter.hpp NodeSortKey.cpp NodeSortKey.hpp

dbertoni    2003/07/09 16:44:13

  Modified:    c/src/xalanc/XSLT ElemForEach.cpp ElemSort.cpp
                        NodeSorter.cpp NodeSorter.hpp NodeSortKey.cpp
                        NodeSortKey.hpp
  Log:
  Optimized sort performance by changing default behavior and by caching string results, instead of XObject results.
  
  Revision  Changes    Path
  1.2       +2 -4      xml-xalan/c/src/xalanc/XSLT/ElemForEach.cpp
  
  Index: ElemForEach.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/xalanc/XSLT/ElemForEach.cpp,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ElemForEach.cpp	29 Jun 2003 03:58:07 -0000	1.1
  +++ ElemForEach.cpp	9 Jul 2003 23:44:12 -0000	1.2
  @@ -2,7 +2,7 @@
    * The Apache Software License, Version 1.1
    *
    *
  - * Copyright (c) 1999-2002 The Apache Software Foundation.  All rights 
  + * Copyright (c) 1999-2003 The Apache Software Foundation.  All rights 
    * reserved.
    *
    * Redistribution and use in source and binary forms, with or without
  @@ -377,12 +377,10 @@
   
   			clear(scratchString);
   
  -			assert(sort->getSelectPattern() != 0);
  -
   			keys.push_back(
   					NodeSortKey(
   						executionContext,
  -						*sort->getSelectPattern(),
  +						sort->getSelectPattern(),
   						treatAsNumbers,
   						descending,
   						caseOrder,
  
  
  
  1.2       +1 -6      xml-xalan/c/src/xalanc/XSLT/ElemSort.cpp
  
  Index: ElemSort.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/xalanc/XSLT/ElemSort.cpp,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ElemSort.cpp	29 Jun 2003 03:58:07 -0000	1.1
  +++ ElemSort.cpp	9 Jul 2003 23:44:12 -0000	1.2
  @@ -2,7 +2,7 @@
    * The Apache Software License, Version 1.1
    *
    *
  - * Copyright (c) 1999-2002 The Apache Software Foundation.  All rights 
  + * Copyright (c) 1999-2003 The Apache Software Foundation.  All rights 
    * reserved.
    *
    * Redistribution and use in source and binary forms, with or without
  @@ -150,11 +150,6 @@
   				c_wstr(Constants::ATTRNAME_ORDER),
   				c_wstr(Constants::ATTRVAL_ORDER_ASCENDING),
   				*this);
  -	}
  -
  -	if(0 == m_selectPattern)
  -	{
  -		m_selectPattern = constructionContext.createXPath(getLocator(), StaticStringToDOMString(XALAN_STATIC_UCODE_STRING(".")), *this);
   	}
   }
   
  
  
  
  1.2       +165 -33   xml-xalan/c/src/xalanc/XSLT/NodeSorter.cpp
  
  Index: NodeSorter.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/xalanc/XSLT/NodeSorter.cpp,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- NodeSorter.cpp	29 Jun 2003 03:58:07 -0000	1.1
  +++ NodeSorter.cpp	9 Jul 2003 23:44:12 -0000	1.2
  @@ -2,7 +2,7 @@
    * The Apache Software License, Version 1.1
    *
    *
  - * Copyright (c) 1999-2002 The Apache Software Foundation.  All rights 
  + * Copyright (c) 1999-2003 The Apache Software Foundation.  All rights 
    * reserved.
    *
    * Redistribution and use in source and binary forms, with or without
  @@ -107,8 +107,8 @@
   	assert(m_scratchVector.empty() == false);
   
   	// Make sure the caches are cleared when we're done...
  -	CollectionClearGuard<NumberResultsCacheType>	guard1(m_numberResultsCache);
  -	CollectionClearGuard<StringResultsCacheType>	guard2(m_stringResultsCache);
  +	const CollectionClearGuard<NumberResultsCacheType>	guard1(m_numberResultsCache);
  +	const CollectionClearGuard<StringResultsCacheType>	guard2(m_stringResultsCache);
   
   	NodeSortKeyCompare	theComparer(
   					executionContext,
  @@ -239,12 +239,12 @@
   	// Compare as numbers
   	if(theKey.getTreatAsNumbers() == false)
   	{
  -		// Compare as strings
  +		// Compare as strings...
   		const XalanDOMString&	theLHSString =
  -			getStringResult(theKey, theKeyIndex, theLHS)->str();
  +			getStringResult(theKey, theKeyIndex, theLHS);
   
   		const XalanDOMString&	theRHSString =
  -			getStringResult(theKey, theKeyIndex, theRHS)->str();
  +			getStringResult(theKey, theKeyIndex, theRHS);
   
   		theResult = doCollationCompare(
   				m_executionContext,
  @@ -255,8 +255,8 @@
   	}
   	else
   	{
  -		double	n1Num = getNumberResult(theKey, theKeyIndex, theLHS);
  -		double	n2Num = getNumberResult(theKey, theKeyIndex, theRHS);
  +		const double	n1Num = getNumberResult(theKey, theKeyIndex, theLHS);
  +		const double	n2Num = getNumberResult(theKey, theKeyIndex, theRHS);
   
   		// Always order NaN before anything else...
   		if (DoubleSupport::isNaN(n1Num) == true)
  @@ -300,6 +300,41 @@
   
   
   
  +inline double
  +getResult(
  +			const XPath*			theXPath,
  +			XalanNode*				theNode,
  +			const PrefixResolver&	thePrefixResolver,
  +			XPathExecutionContext&	theExecutionContext)
  +{
  +	typedef StylesheetExecutionContext::GetAndReleaseCachedString	GetAndReleaseCachedString;
  +
  +	if (theXPath == 0)
  +	{
  +		assert(theNode != 0);
  +
  +		const GetAndReleaseCachedString		temp(theExecutionContext);
  +
  +		DOMServices::getNodeData(*theNode, temp.get());
  +
  +		return DoubleSupport::toDouble(temp.get());
  +	}
  +	else
  +	{
  +		double	theResult;
  +
  +		theXPath->execute(
  +				theNode,
  +				thePrefixResolver,
  +				theExecutionContext,
  +				theResult);
  +
  +		return theResult;
  +	}
  +}
  +
  +
  +
   double
   NodeSorter::NodeSortKeyCompare::getNumberResult(
   				const NodeSortKey&		theKey,
  @@ -309,7 +344,6 @@
   	assert(theKey.getPrefixResolver() != 0);
   
   	const XPath* const	xpath = theKey.getSelectPattern();
  -	assert(xpath != 0);
   
   	typedef	NodeSorter::NumberResultsCacheType	NumberResultsCacheType;
   
  @@ -332,14 +366,13 @@
   	{
   		if (DoubleSupport::equal(theCache[theKeyIndex][theEntry.m_position], theDummyValue) == true)
   		{
  -			xpath->execute(
  -				theEntry.m_node,
  -				*theKey.getPrefixResolver(),
  -				m_executionContext,
  -				theCache[theKeyIndex][theEntry.m_position]);
  +			theCache[theKeyIndex][theEntry.m_position] =
  +				getResult(
  +					xpath,
  +					theEntry.m_node,
  +					*theKey.getPrefixResolver(),
  +					m_executionContext);
   		}
  -
  -		return theCache[theKeyIndex][theEntry.m_position];
   	}
   	else
   	{
  @@ -353,17 +386,113 @@
   			theCache[theKeyIndex].end(),
   			theDummyValue);
   
  -		double&		theResult = theCache[theKeyIndex][theEntry.m_position];
  +		theCache[theKeyIndex][theEntry.m_position] =
  +			getResult(
  +				xpath,
  +				theEntry.m_node,
  +				*theKey.getPrefixResolver(),
  +				m_executionContext);
  +	}
  +
  +	return theCache[theKeyIndex][theEntry.m_position];
  +}
   
  -		xpath->execute(theEntry.m_node, *theKey.getPrefixResolver(), m_executionContext, theResult);
   
  -		return theResult;
  +
  +#if defined(XALAN_NODESORTER_CACHE_XOBJECTS)
  +
  +inline void
  +getResult(
  +			const XPath*			theXPath,
  +			XalanNode*				theNode,
  +			const PrefixResolver&	thePrefixResolver,
  +			XPathExecutionContext&	theExecutionContext,
  +			XObjectPtr&				theResult)
  +{
  +	if (theXPath == 0)
  +	{
  +		assert(theNode != 0);
  +
  +		theResult = theExecutionContext.getXObjectFactory().createNodeSet(theNode);		
  +	}
  +	else
  +	{
  +		theResult = theXPath->execute(
  +				theNode,
  +				thePrefixResolver,
  +				theExecutionContext);
   	}
   }
   
  +inline bool
  +notCached(const XObjectPtr&		theEntry)
  +{
  +	return theEntry.null();
  +}
  +
  +inline bool
  +isCached(const XObjectPtr&	theEntry)
  +{
  +	return !theEntry.null();
  +}
  +
  +inline const XalanDOMString&
  +cacheValue(const XObjectPtr&	theEntry)
  +{
  +	return theEntry->str();
  +}
  +
  +#else
  +
  +inline void
  +getResult(
  +			const XPath*			theXPath,
  +			XalanNode*				theNode,
  +			const PrefixResolver&	thePrefixResolver,
  +			XPathExecutionContext&	theExecutionContext,
  +			XalanDOMString&			theResult)
  +{
  +	if (theXPath == 0)
  +	{
  +		assert(theNode != 0);
  +
  +		DOMServices::getNodeData(
  +				*theNode,
  +				theResult);
  +	}
  +	else
  +	{
  +		theXPath->execute(
  +				theNode,
  +				thePrefixResolver,
  +				theExecutionContext,
  +				theResult);
  +	}
  +}
  +
  +inline bool
  +notCached(const XalanDOMString&		theEntry)
  +{
  +	return theEntry.empty();
  +}
  +
  +inline bool
  +isCached(const XalanDOMString&	/* theEntry */)
  +{
  +	return true;
  +}
  +
  +inline const XalanDOMString&
  +cacheValue(const XalanDOMString&	theEntry)
  +{
  +	return theEntry;
  +}
  +
  +#endif
   
   
  -const XObjectPtr&
  +
  +const XalanDOMString&
   NodeSorter::NodeSortKeyCompare::getStringResult(
   				const NodeSortKey&		theKey,
   				unsigned int			theKeyIndex,
  @@ -372,7 +501,6 @@
   	assert(theKey.getPrefixResolver() != 0);
   
   	const XPath* const	xpath = theKey.getSelectPattern();
  -	assert(xpath != 0);
   
   	typedef	NodeSorter::StringResultsCacheType	StringResultsCacheType;
   
  @@ -386,27 +514,31 @@
   
   	if (theCache[theKeyIndex].empty() == false)
   	{
  -		if (theCache[theKeyIndex][theEntry.m_position].null() == true)
  +		if (notCached(theCache[theKeyIndex][theEntry.m_position]) == true)
   		{
  -			theCache[theKeyIndex][theEntry.m_position] =
  -				xpath->execute(theEntry.m_node, *theKey.getPrefixResolver(), m_executionContext);
  +			getResult(
  +				xpath,
  +				theEntry.m_node,
  +				*theKey.getPrefixResolver(),
  +				m_executionContext,
  +				theCache[theKeyIndex][theEntry.m_position]);
   		}
  -
  -		assert(theCache[theKeyIndex][theEntry.m_position].null() == false);
  -
  -		return theCache[theKeyIndex][theEntry.m_position];
   	}
   	else
   	{
   		theCache[theKeyIndex].resize(m_nodes.size());
   
  -		theCache[theKeyIndex][theEntry.m_position] =
  -			xpath->execute(theEntry.m_node, *theKey.getPrefixResolver(), m_executionContext);
  +		getResult(
  +			xpath,
  +			theEntry.m_node,
  +			*theKey.getPrefixResolver(),
  +			m_executionContext,
  +			theCache[theKeyIndex][theEntry.m_position]);
  +	}
   
  -		assert(theCache[theKeyIndex][theEntry.m_position].null() == false);
  +	assert(isCached(theCache[theKeyIndex][theEntry.m_position]) == true);
   
  -		return theCache[theKeyIndex][theEntry.m_position];
  -	}
  +	return cacheValue(theCache[theKeyIndex][theEntry.m_position]);
   }
   
   
  
  
  
  1.2       +23 -13    xml-xalan/c/src/xalanc/XSLT/NodeSorter.hpp
  
  Index: NodeSorter.hpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/xalanc/XSLT/NodeSorter.hpp,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- NodeSorter.hpp	29 Jun 2003 03:58:07 -0000	1.1
  +++ NodeSorter.hpp	9 Jul 2003 23:44:12 -0000	1.2
  @@ -2,7 +2,7 @@
    * The Apache Software License, Version 1.1
    *
    *
  - * Copyright (c) 1999-2002 The Apache Software Foundation.  All rights 
  + * Copyright (c) 1999-2003 The Apache Software Foundation.  All rights 
    * reserved.
    *
    * Redistribution and use in source and binary forms, with or without
  @@ -58,7 +58,6 @@
   #define XALAN_NODESORTER_HEADER_GUARD
   
   /**
  - * @author Scott Boag (scott_boag@lotus.com)
    * @author David N. Bertoni (david_n_bertoni@lotus.com)
    */
   
  @@ -91,7 +90,7 @@
   class XalanNode;
   class XPath;
   
  -
  +#define XALAN_NODESORTER_CACHE_XOBJECTS
   
   /**
    * This class can sort vectors of nodes according to a select pattern.
  @@ -217,7 +216,7 @@
   				unsigned int			theKeyIndex,
   				first_argument_type		theEntry) const;
   
  -		const XObjectPtr&
  +		const XalanDOMString&
   		getStringResult(
   				const NodeSortKey&		theKey,
   				unsigned int			theKeyIndex,
  @@ -234,18 +233,29 @@
   	friend struct NodeSortKeyCompare;
   
   #if defined(XALAN_NO_STD_NAMESPACE)
  -	typedef	vector<double>		NumberResultsCacheVectorType;
  +	typedef	vector<double>			NumberVectorType;
  +	typedef	vector<XObjectPtr>		XObjectVectorType;
  +	typedef	vector<XalanDOMString>	StringVectorType;
  +
  +	typedef vector<NumberVectorType>	NumberCacheType;
  +	typedef vector<XObjectVectorType>	XObjectCacheType;
  +	typedef vector<StringVectorType>	StringCacheType;
  +#else
  +	typedef	std::vector<double>			NumberVectorType;
  +	typedef	std::vector<XObjectPtr>		XObjectVectorType;
  +	typedef	std::vector<XalanDOMString>	StringVectorType;
  +
  +	typedef std::vector<NumberVectorType>	NumberCacheType;
  +	typedef std::vector<XObjectVectorType>	XObjectCacheType;
  +	typedef std::vector<StringVectorType>	StringCacheType;
  +#endif
   
  -	typedef	vector<XObjectPtr>	StringResultsCacheVectorType;
  +	typedef NumberCacheType		NumberResultsCacheType;
   
  -	typedef vector<NumberResultsCacheVectorType>	NumberResultsCacheType;
  -	typedef vector<StringResultsCacheVectorType>	StringResultsCacheType;
  +#if defined(XALAN_NODESORTER_CACHE_XOBJECTS)
  +	typedef XObjectCacheType	StringResultsCacheType;
   #else
  -	typedef	std::vector<double>			NumberResultsCacheVectorType;
  -	typedef	std::vector<XObjectPtr>		StringResultsCacheVectorType;
  -
  -	typedef std::vector<NumberResultsCacheVectorType>	NumberResultsCacheType;
  -	typedef std::vector<StringResultsCacheVectorType>	StringResultsCacheType;
  +	typedef StringCacheType		StringResultsCacheType;
   #endif
   
   private:
  
  
  
  1.2       +3 -3      xml-xalan/c/src/xalanc/XSLT/NodeSortKey.cpp
  
  Index: NodeSortKey.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/xalanc/XSLT/NodeSortKey.cpp,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- NodeSortKey.cpp	29 Jun 2003 03:58:07 -0000	1.1
  +++ NodeSortKey.cpp	9 Jul 2003 23:44:12 -0000	1.2
  @@ -2,7 +2,7 @@
    * The Apache Software License, Version 1.1
    *
    *
  - * Copyright (c) 1999-2002 The Apache Software Foundation.  All rights 
  + * Copyright (c) 1999-2003 The Apache Software Foundation.  All rights 
    * reserved.
    *
    * Redistribution and use in source and binary forms, with or without
  @@ -76,14 +76,14 @@
   
   NodeSortKey::NodeSortKey(
   			ExecutionContext&		executionContext,
  -			const XPath&			selectPat,
  +			const XPath*			selectPat,
   			bool					treatAsNumbers,
   			bool					descending,
   			eCaseOrder				caseOrder,
   			const XalanDOMString&	langValue,
   			const PrefixResolver&	resolver) :
   	m_executionContext(&executionContext),
  -	m_selectPat(&selectPat),
  +	m_selectPat(selectPat),
   	m_treatAsNumbers(treatAsNumbers),
   	m_descending(descending),
   	m_caseOrder(caseOrder),
  
  
  
  1.2       +2 -2      xml-xalan/c/src/xalanc/XSLT/NodeSortKey.hpp
  
  Index: NodeSortKey.hpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/xalanc/XSLT/NodeSortKey.hpp,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- NodeSortKey.hpp	29 Jun 2003 03:58:07 -0000	1.1
  +++ NodeSortKey.hpp	9 Jul 2003 23:44:12 -0000	1.2
  @@ -2,7 +2,7 @@
    * The Apache Software License, Version 1.1
    *
    *
  - * Copyright (c) 1999-2002 The Apache Software Foundation.  All rights 
  + * Copyright (c) 1999-2003 The Apache Software Foundation.  All rights 
    * reserved.
    *
    * Redistribution and use in source and binary forms, with or without
  @@ -111,7 +111,7 @@
   	 */
   	NodeSortKey(
   			ExecutionContext&		executionContext,
  -			const XPath&			selectPat, 
  +			const XPath*			selectPat, 
   			bool					treatAsNumbers, 
   			bool					descending,
   			eCaseOrder				caseOrder,
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: xalan-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xalan-cvs-help@xml.apache.org