From 20538c25129ebadfa2050c0071887e1e2a46c838 Mon Sep 17 00:00:00 2001 From: Matúš Kukan Date: Fri, 26 Sep 2014 17:17:50 +0200 Subject: FastSerializer: Avoid sequences where possible Change-Id: I359ca9d3b766b71904e4199ebfbdbd5b203775cc --- comphelper/source/streaming/seqstream.cxx | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) (limited to 'comphelper/source/streaming') diff --git a/comphelper/source/streaming/seqstream.cxx b/comphelper/source/streaming/seqstream.cxx index aec451986075..91fdc7d73378 100644 --- a/comphelper/source/streaming/seqstream.cxx +++ b/comphelper/source/streaming/seqstream.cxx @@ -156,14 +156,19 @@ OSequenceOutputStream::OSequenceOutputStream(Sequence< sal_Int8 >& _rSeq, double // this heuristic is as good as any other ... supply better parameters if you don't like it :) } - void SAL_CALL OSequenceOutputStream::writeBytes( const Sequence< sal_Int8 >& _rData ) throw(NotConnectedException, BufferSizeExceededException, IOException, RuntimeException, std::exception) +{ + writeBytes(_rData.getConstArray(), _rData.getLength()); +} + +void SAL_CALL OSequenceOutputStream::writeBytes( const sal_Int8* pStr, sal_Int32 nLen ) + throw(NotConnectedException, BufferSizeExceededException, IOException, RuntimeException, std::exception) { if (!m_bConnected) throw NotConnectedException(); // ensure the sequence has enough space left - if (m_nSize + _rData.getLength() > m_rSequence.getLength()) + if (m_nSize + nLen > m_rSequence.getLength()) { sal_Int32 nCurrentLength = m_rSequence.getLength(); sal_Int32 nNewLength = static_cast< sal_Int32 >( @@ -177,18 +182,18 @@ void SAL_CALL OSequenceOutputStream::writeBytes( const Sequence< sal_Int8 >& _rD // such a large step is not allowed nNewLength = nCurrentLength + m_nMaximumResize; - if (nNewLength < m_nSize + _rData.getLength()) + if (nNewLength < m_nSize + nLen) { // it's not enough .... the data would not fit // let's take the double amount of the length of the data to be written, as the next write // request could be as large as this one - sal_Int32 nNewGrowth = _rData.getLength() * 2; + sal_Int32 nNewGrowth = nLen * 2; if ((m_nMaximumResize > 0) && (nNewGrowth > m_nMaximumResize)) { // we came to the limit, again ... nNewGrowth = m_nMaximumResize; - if (nNewGrowth + nCurrentLength < m_nSize + _rData.getLength()) + if (nNewGrowth + nCurrentLength < m_nSize + nLen) // but it would not fit if we respect the limit - nNewGrowth = m_nSize + _rData.getLength() - nCurrentLength; + nNewGrowth = m_nSize + nLen - nCurrentLength; } nNewLength = nCurrentLength + nNewGrowth; } @@ -199,11 +204,11 @@ void SAL_CALL OSequenceOutputStream::writeBytes( const Sequence< sal_Int8 >& _rD m_rSequence.realloc(nNewLength); } - OSL_ENSURE(m_rSequence.getLength() >= m_nSize + _rData.getLength(), + OSL_ENSURE(m_rSequence.getLength() >= m_nSize + nLen, "ooops ... the realloc algorithm seems to be wrong :( !"); - memcpy(m_rSequence.getArray() + m_nSize, _rData.getConstArray(), _rData.getLength()); - m_nSize += _rData.getLength(); + memcpy(m_rSequence.getArray() + m_nSize, pStr, nLen); + m_nSize += nLen; } -- cgit