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 2001/03/30 00:13:06 UTC

cvs commit: xml-xalan/c/src/XalanDOM XalanDOMString.cpp XalanDOMString.hpp

dbertoni    01/03/29 14:13:06

  Modified:    c/src/XalanDOM XalanDOMString.cpp XalanDOMString.hpp
  Log:
  Enabled caching of size and fixed a few bugs related to caching.
  
  Revision  Changes    Path
  1.9       +126 -3    xml-xalan/c/src/XalanDOM/XalanDOMString.cpp
  
  Index: XalanDOMString.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/XalanDOM/XalanDOMString.cpp,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- XalanDOMString.cpp	2001/02/08 21:41:01	1.8
  +++ XalanDOMString.cpp	2001/03/29 22:13:05	1.9
  @@ -190,6 +190,109 @@
   
   
   
  +void
  +XalanDOMString::resize(
  +			size_type		theCount,
  +			XalanDOMChar	theChar)
  +{
  +	invariants();
  +
  +	const size_type		theOldSize = size();
  +
  +	if (theCount != theOldSize)
  +	{
  +		if (theOldSize == 0)
  +		{
  +			// If the string is of 0 length, resize but add an
  +			// extra byte for the terminating byte.
  +			m_data.resize(theCount + 1, theChar);
  +		}
  +		else
  +		{
  +			// If the string is not of 0 length, resize but
  +			// put a copy of theChar where the terminating
  +			// byte used to be.
  +			m_data.resize(theCount, theChar);
  +
  +			m_data[theOldSize] = theChar;
  +		}
  +
  +#if defined(XALAN_DOMSTRING_CACHE_SIZE)
  +		m_size = theCount;
  +#endif
  +
  +		// Terminate...
  +		m_data.back() = 0;
  +	}
  +
  +	invariants();
  +}
  +
  +
  +
  +void
  +XalanDOMString::erase(
  +			size_type	theStartPosition,
  +			size_type	theCount)
  +{
  +	invariants();
  +
  +	const size_type		theActualCount =
  +			theCount == size_type(npos) ? length() : theCount;
  +
  +	if (theStartPosition == 0 && theCount >= size())
  +	{
  +		m_data.erase(m_data.begin(), m_data.end());
  +
  +#if defined(XALAN_DOMSTRING_CACHE_SIZE)
  +		m_size = 0;
  +#endif
  +	}
  +	else
  +	{
  +		const iterator		i = getIteratorForPosition(theStartPosition);
  +
  +		m_data.erase(i, i + (theActualCount));
  +
  +#if defined(XALAN_DOMSTRING_CACHE_SIZE)
  +		const size_type		theNewSize = m_data.size();
  +
  +		if (theNewSize < 2)
  +		{
  +			m_size = 0;
  +		}
  +		else
  +		{
  +			m_size = theNewSize - 1;
  +		}
  +#endif
  +	}
  +
  +	invariants();
  +}
  +
  +
  +
  +XalanDOMString&
  +XalanDOMString::assign(
  +		const_iterator	theFirstPosition,
  +		const_iterator	theLastPosition)
  +{
  +	invariants();
  +
  +	erase();
  +
  +	invariants();
  +
  +	insert(begin(), theFirstPosition, theLastPosition);
  +
  +	invariants();
  +
  +	return *this;
  +}
  +
  +
  +
   XalanDOMString&
   XalanDOMString::append(
   			const XalanDOMChar*		theString,
  @@ -452,7 +555,7 @@
   
   
   
  -static inline unsigned int
  +static inline XalanDOMString::size_type
   length(const XalanDOMChar*	theString)
   {
   	assert(theString != 0);
  @@ -472,9 +575,9 @@
   bool
   XalanDOMString::equals(
   			const XalanDOMChar*		theLHS,
  -			unsigned int			theLHSLength,
  +			size_type				theLHSLength,
   			const XalanDOMChar*		theRHS,
  -			unsigned int			theRHSLength)
  +			size_type				theRHSLength)
   {
   	if (theLHSLength != theRHSLength)
   	{
  @@ -503,6 +606,26 @@
   		}
   
   		return false;
  +	}
  +}
  +
  +
  +
  +bool
  +XalanDOMString::equals(
  +			const XalanDOMString&	theLHS,
  +			const XalanDOMString&	theRHS)
  +{
  +	const XalanDOMString::size_type		theLHSLength = theLHS.size();
  +	const XalanDOMString::size_type		theRHSLength = theRHS.size();
  +
  +	if (theLHSLength != theRHSLength)
  +	{
  +		return false;
  +	}
  +	else
  +	{
  +		return equals(theLHS.c_str(), theLHSLength, theRHS.c_str(), theRHSLength);
   	}
   }
   
  
  
  
  1.12      +12 -93    xml-xalan/c/src/XalanDOM/XalanDOMString.hpp
  
  Index: XalanDOMString.hpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/XalanDOM/XalanDOMString.hpp,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- XalanDOMString.hpp	2001/02/08 21:41:03	1.11
  +++ XalanDOMString.hpp	2001/03/29 22:13:06	1.12
  @@ -72,7 +72,7 @@
   
   
   
  -//#define XALAN_DOMSTRING_CACHE_SIZE
  +#define XALAN_DOMSTRING_CACHE_SIZE
   
   
   
  @@ -233,37 +233,7 @@
   	void
   	resize(
   			size_type		theCount,
  -			XalanDOMChar	theChar)
  -	{
  -		invariants();
  -
  -		const size_type		theOldSize = size();
  -
  -		if (theOldSize == 0)
  -		{
  -			// If the string is of 0 length, resize but add an
  -			// extra byte for the terminating byte.
  -			m_data.resize(theCount + 1, theChar);
  -		}
  -		else
  -		{
  -			// If the string is not of 0 length, resize but
  -			// put a copy of theChar where the terminating
  -			// byte used to be.
  -			m_data.resize(theCount, theChar);
  -
  -			m_data[theOldSize] = theChar;
  -		}
  -
  -#if defined(XALAN_DOMSTRING_CACHE_SIZE)
  -		m_size += theCount;
  -#endif
  -
  -		// Terminate...
  -		m_data.back() = 0;
  -
  -		invariants();
  -	}
  +			XalanDOMChar	theChar);
   
   	void
   	resize(size_type	theCount)
  @@ -306,41 +276,18 @@
   	void
   	erase(
   			size_type	theStartPosition = 0,
  -			size_type	theCount = size_type(npos))
  -	{
  -		invariants();
  -
  -		const size_type		theActualCount =
  -			theCount == size_type(npos) ? length() : theCount;
  -
  -		if (theStartPosition == 0 && theCount == size())
  -		{
  -			m_data.erase(m_data.begin(), m_data.end());
  -
  -#if defined(XALAN_DOMSTRING_CACHE_SIZE)
  -			m_size = 0;
  -#endif
  -		}
  -		else
  -		{
  -			const iterator		i = getIteratorForPosition(theStartPosition);
  -
  -			m_data.erase(i, i + (theActualCount));
  -
  -#if defined(XALAN_DOMSTRING_CACHE_SIZE)
  -			m_size -= theActualCount;
  -#endif
  -		}
  -
  -		invariants();
  -	}
  +			size_type	theCount = size_type(npos));
   
   	bool
   	empty() const
   	{
   		invariants();
   
  +#if defined(XALAN_DOMSTRING_CACHE_SIZE)
  +		return m_size == 0 ? true : false;
  +#else
   		return m_data.size() < 2 ? true : false;
  +#endif
   	}
   
   	const_reference
  @@ -451,8 +398,6 @@
   		invariants();
   
   		return append(theSource);
  -
  -		invariants();
   	}
   
   	XalanDOMString&
  @@ -513,20 +458,7 @@
   	XalanDOMString&
   	assign(
   		const_iterator	theFirstPosition,
  -		const_iterator	theLastPosition)
  -	{
  -		invariants();
  -
  -		erase();
  -
  -		invariants();
  -
  -		insert(begin(), theFirstPosition, theLastPosition);
  -
  -		invariants();
  -
  -		return *this;
  -	}
  +		const_iterator	theLastPosition);
   
   	XalanDOMString&
   	append(const XalanDOMString&	theSource)
  @@ -719,9 +651,9 @@
   	static bool
   	equals(
   			const XalanDOMChar*		theLHS,
  -			unsigned int			theLHSLength,
  +			size_type				theLHSLength,
   			const XalanDOMChar*		theRHS,
  -			unsigned int			theRHSLength);
  +			size_type				theRHSLength);
   
   	static bool
   	equals(
  @@ -734,20 +666,7 @@
   	static bool
   	equals(
   			const XalanDOMString&	theLHS,
  -			const XalanDOMString&	theRHS)
  -	{
  -		const unsigned int	theLHSLength = theLHS.size();
  -		const unsigned int	theRHSLength = theRHS.size();
  -
  -		if (theLHSLength != theRHSLength)
  -		{
  -			return false;
  -		}
  -		else
  -		{
  -			return equals(theLHS.c_str(), theLHSLength, theRHS.c_str(), theRHSLength);
  -		}
  -	}
  +			const XalanDOMString&	theRHS);
   
   	static bool
   	equals(
  @@ -788,7 +707,7 @@
   #if !defined(NDEBUG)
   
   #if defined(XALAN_DOMSTRING_CACHE_SIZE)
  -		assert(m_data.size() == 0 || m_size == m_data.size() - 1);
  +		assert((m_data.size() == 0 && m_size == 0) || m_size == m_data.size() - 1);
   #endif
   
   		assert(m_data.size() == 0 || m_data.back() == 0);
  
  
  

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