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/08/28 03:17:17 UTC

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

dbertoni    00/08/27 18:17:17

  Modified:    c/src/XPath QName.cpp QName.hpp
  Log:
  Return references to strings, instead of copies.
  
  Revision  Changes    Path
  1.10      +40 -23    xml-xalan/c/src/XPath/QName.cpp
  
  Index: QName.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/XPath/QName.cpp,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- QName.cpp	2000/08/22 20:20:46	1.9
  +++ QName.cpp	2000/08/28 01:17:16	1.10
  @@ -75,6 +75,10 @@
   
   
   
  +const XalanDOMString	QName::s_emptyString;
  +
  +
  +
   QName::QName(
   			const XalanDOMString&	theNamespace,
   			const XalanDOMString&	theLocalPart) :
  @@ -193,17 +197,17 @@
   
   
   
  -XalanDOMString
  +const XalanDOMString&
   QName::getNamespaceForPrefix(
   			const NamespaceVectorType&	namespaces,
   			const XalanDOMString&		prefix,
   			bool						reverse)
   {
  -	XalanDOMString	nsURI;
  +	const XalanDOMString*	nsURI = &s_emptyString;
   
   	if(::equals(prefix, DOMServices::s_XMLString))
   	{
  -		nsURI = DOMServices::s_XMLNamespaceURI;
  +		nsURI = &DOMServices::s_XMLNamespaceURI;
   	}
   	else
   	{
  @@ -215,7 +219,9 @@
   				const XalanDOMString& thisPrefix = ns.getPrefix();
   				if(::equals(prefix, thisPrefix))
   				{
  -					return ns.getURI();
  +					nsURI = &ns.getURI();
  +
  +					break;
   				}
   			}
   		}
  @@ -227,46 +233,53 @@
   				const XalanDOMString& thisPrefix = ns.getPrefix();
   				if(::equals(prefix, thisPrefix))
   				{
  -					return ns.getURI();
  +					nsURI = &ns.getURI();
  +
  +					break;
   				}
   			}
   		}
   	}
  -	return nsURI;
  +
  +	assert(nsURI != 0);
  +
  +	return *nsURI;
   }
   
   
   
  -XalanDOMString
  +const XalanDOMString&
   QName::getNamespaceForPrefix(
   			const NamespacesStackType&	nsStack,
   			const XalanDOMString&		prefix,
   			bool						reverse)
   {
  -	XalanDOMString	nsURI;
  +	const XalanDOMString*	nsURI = &s_emptyString;
   
   	const int depth = nsStack.size();
   
   	for(int i = depth-1; i >= 0; i--)
   	{
   		const NamespaceVectorType& namespaces = nsStack[i];
  -		nsURI = QName::getNamespaceForPrefix(namespaces, prefix, reverse);
  -		if (! ::isEmpty(nsURI))
  +		nsURI = &QName::getNamespaceForPrefix(namespaces, prefix, reverse);
  +		if (! ::isEmpty(*nsURI))
   			break;
   	}
  +
  +	assert(nsURI != 0);
   
  -	return nsURI;
  +	return *nsURI;
   }
   
  +
   
  -      
  -XalanDOMString
  +const XalanDOMString&
   QName::getPrefixForNamespace(
   			const NamespaceVectorType&	namespaces,
   			const XalanDOMString&		uri,
   			bool						/* reverse */)
   {
  -	XalanDOMString	thePrefix;
  +	const XalanDOMString*	thePrefix = &s_emptyString;
   
   	for(int j = namespaces.size()-1; j >= 0; j--)
   	{
  @@ -275,24 +288,26 @@
   
   		if(::equals(uri, thisURI))
   		{
  -			thePrefix = ns.getPrefix();
  +			thePrefix = &ns.getPrefix();
   
   			break;
   		}
   	}
   
  -	return thePrefix;
  +	assert(thePrefix != 0);
  +
  +	return *thePrefix;
   }		
   
   
   
  -XalanDOMString
  +const XalanDOMString&
   QName::getPrefixForNamespace(
   			const NamespacesStackType&	nsStack,
   			const XalanDOMString&		uri,
   			bool						reverse)
   {
  -	XalanDOMString	prefix;
  +	const XalanDOMString*	thePrefix = &s_emptyString;
   
   	const int		depth = nsStack.size();
   
  @@ -301,8 +316,8 @@
   		for(int i = depth-1; i >= 0; i--)
   		{
   			const NamespaceVectorType& namespaces = nsStack[i];
  -			prefix = QName::getPrefixForNamespace(namespaces, uri, reverse);
  -			if (! ::isEmpty(prefix))
  +			thePrefix = &QName::getPrefixForNamespace(namespaces, uri, reverse);
  +			if (! ::isEmpty(*thePrefix))
   				break;
   		}
   	}
  @@ -311,11 +326,13 @@
   		for(int i = 0; i < depth; i++)
   		{
   			const NamespaceVectorType& namespaces = nsStack[i];
  -			prefix = QName::getPrefixForNamespace(namespaces, uri, reverse);
  -			if (! ::isEmpty(prefix))
  +			thePrefix = &QName::getPrefixForNamespace(namespaces, uri, reverse);
  +			if (! ::isEmpty(*thePrefix))
   				break;
   		}
   	}
  +
  +	assert(thePrefix != 0);
   
  -	return prefix;
  +	return *thePrefix;
   }
  
  
  
  1.9       +22 -8     xml-xalan/c/src/XPath/QName.hpp
  
  Index: QName.hpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/XPath/QName.hpp,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- QName.hpp	2000/08/22 20:20:46	1.8
  +++ QName.hpp	2000/08/28 01:17:16	1.9
  @@ -222,8 +222,11 @@
   	 * @param prefix     namespace prefix to find
   	 * @param reverse    true to search vector from last to first, default true
   	 */
  -	static XalanDOMString getNamespaceForPrefix(const NamespaceVectorType& namespaces,
  -			const XalanDOMString& prefix, bool reverse=true);
  +	static const XalanDOMString&
  +	getNamespaceForPrefix(
  +			const NamespaceVectorType&	namespaces,
  +			const XalanDOMString&		prefix,
  +			bool						reverse = true);
   
   	/**
   	 * Get the namespace from a prefix by searching a stack of namespace
  @@ -233,8 +236,11 @@
   	 * @param prefix  namespace prefix to find
   	 * @param reverse true to search vector from last to first, default true
   	 */
  -	static XalanDOMString getNamespaceForPrefix(const NamespacesStackType& nsStack,
  -			const XalanDOMString& prefix, bool reverse=true);
  +	static const XalanDOMString&
  +	getNamespaceForPrefix(
  +			const NamespacesStackType&	nsStack,
  +			const XalanDOMString&		prefix,
  +			bool						reverse = true);
   
   	/**
   	 * Get the prefix for a namespace by searching a vector of namespaces.
  @@ -243,8 +249,11 @@
   	 * @param uri        URI string for namespace to find
   	 * @param reverse    true to search vector from last to first, default true
   	 */
  -	static XalanDOMString getPrefixForNamespace(const NamespaceVectorType& namespaces,
  -			const XalanDOMString& uri, bool reverse=true);
  +	static const XalanDOMString&
  +	getPrefixForNamespace(
  +			const NamespaceVectorType&	namespaces,
  +			const XalanDOMString&		uri,
  +			bool						reverse = true);
   
   	/**
   	 * Get the prefix for a namespace by searching a stack of namespace
  @@ -254,8 +263,11 @@
   	 * @param uri     URI string for namespace to find
   	 * @param reverse true to search vector from last to first, default true
   	 */
  -	static XalanDOMString getPrefixForNamespace(const NamespacesStackType& nsStack,
  -			const XalanDOMString& uri, bool reverse=true);
  +	static const XalanDOMString&
  +	getPrefixForNamespace(
  +			const NamespacesStackType&	nsStack,
  +			const XalanDOMString&		uri,
  +			bool						reverse = true);
   
   private:
   
  @@ -267,6 +279,8 @@
   	XalanDOMString	m_namespace;
   
   	XalanDOMString	m_localpart;
  +
  +	static const XalanDOMString		s_emptyString;
   };