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/02/13 01:12:19 UTC

cvs commit: xml-xalan/c/src/XPath FunctionID.cpp

dbertoni    2003/02/12 16:12:19

  Modified:    c/src/XPath FunctionID.cpp
  Log:
  More efficient implementation when only one token is involved.
  
  Revision  Changes    Path
  1.13      +33 -16    xml-xalan/c/src/XPath/FunctionID.cpp
  
  Index: FunctionID.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/XPath/FunctionID.cpp,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- FunctionID.cpp	24 Jan 2003 02:32:37 -0000	1.12
  +++ FunctionID.cpp	13 Feb 2003 00:12:19 -0000	1.13
  @@ -113,37 +113,54 @@
   									context->getOwnerDocument();
   	assert(theDocContext != 0);
   
  -	typedef XPathExecutionContext::BorrowReturnMutableNodeRefList	BorrowReturnMutableNodeRefList;
  -
  -	// This list will hold the nodes we find.
  -	BorrowReturnMutableNodeRefList	theNodeList(executionContext);
  -
  -	if (length(theResultString) > 0)
  +	if (theResultString.size() == 0)
  +	{
  +		return executionContext.getXObjectFactory().createNodeSet(0);
  +	}
  +	else
   	{
   		StringTokenizer		theTokenizer(theResultString);
   
   		GetAndReleaseCachedString	theGuard2(executionContext);
   
  -		XalanDOMString&				theToken = theGuard2.get();
  +		XalanDOMString&		theToken = theGuard2.get();
   
  -		// Parse the result string...
  -		while(theTokenizer.hasMoreTokens() == true)
  +		StringTokenizer::size_type	theTokenCount = theTokenizer.countTokens();
  +
  +		if (theTokenCount == 1)
   		{
   			theTokenizer.nextToken(theToken);
   
  -			if (length(theToken) > 0)
  +			return executionContext.getXObjectFactory().createNodeSet(theDocContext->getElementById(theToken));
  +		}
  +		else
  +		{
  +			assert(theTokenCount != 0);
  +
  +			typedef XPathExecutionContext::BorrowReturnMutableNodeRefList	BorrowReturnMutableNodeRefList;
  +
  +			// This list will hold the nodes we find.
  +			BorrowReturnMutableNodeRefList	theNodeList(executionContext);
  +
  +			// Parse the result string...
  +			while(theTokenCount-- > 0)
   			{
  -				XalanNode* const	theNode = theDocContext->getElementById(theToken);
  +				theTokenizer.nextToken(theToken);
   
  -				if (theNode != 0)
  +				if (length(theToken) > 0)
   				{
  -					theNodeList->addNodeInDocOrder(theNode, executionContext);
  +					XalanNode* const	theNode = theDocContext->getElementById(theToken);
  +
  +					if (theNode != 0)
  +					{
  +						theNodeList->addNodeInDocOrder(theNode, executionContext);
  +					}
   				}
   			}
  +
  +			return executionContext.getXObjectFactory().createNodeSet(theNodeList);
   		}
   	}
  -
  -	return executionContext.getXObjectFactory().createNodeSet(theNodeList);
   }
   
   
  @@ -163,7 +180,7 @@
   const XalanDOMString
   FunctionID::getError() const
   {
  -	return StaticStringToDOMString(XALAN_STATIC_UCODE_STRING("The id() function takes one argument!"));
  +	return StaticStringToDOMString(XALAN_STATIC_UCODE_STRING("The id() function takes one argument"));
   }
   
   
  
  
  

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