Revert recent changes to comphelper::OSequenceOutputStream

Some of the changes could be wrong and we don't need them.

This reverts commit 784d4bea86d8cbb3a855e557c465ce50a049cefc.
This reverts commit 8524d5aba59148eef94859289f00ab6477e0e821.
This reverts commit 018f1deae884febbbe639c7ee46b45ce4807e9d3.
This reverts commit 8124fddc5803b4e104d4fc2456cb92cb030d9436.

We use our own helper cache class in FastSaxSerializer
since f736eba5a9df8645849a37b08d2764a5f495ab45.

Change-Id: Iaca6b5b11cb32595db4420a02fa72b0007cf6286
This commit is contained in:
Matúš Kukan 2014-09-29 16:31:24 +02:00
parent ea052e766a
commit d45607c4be
2 changed files with 32 additions and 34 deletions

View file

@ -156,19 +156,15 @@ 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)
{
MutexGuard aGuard(m_aMutex);
if (!m_bConnected)
throw NotConnectedException();
// ensure the sequence has enough space left
if (m_nSize + nLen > m_rSequence.getLength())
if (m_nSize + _rData.getLength() > m_rSequence.getLength())
{
sal_Int32 nCurrentLength = m_rSequence.getLength();
sal_Int32 nNewLength = static_cast< sal_Int32 >(
@ -182,18 +178,18 @@ void SAL_CALL OSequenceOutputStream::writeBytes( const sal_Int8* pStr, sal_Int32
// such a large step is not allowed
nNewLength = nCurrentLength + m_nMaximumResize;
if (nNewLength < m_nSize + nLen)
if (nNewLength < m_nSize + _rData.getLength())
{ // 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 = nLen * 2;
sal_Int32 nNewGrowth = _rData.getLength() * 2;
if ((m_nMaximumResize > 0) && (nNewGrowth > m_nMaximumResize))
{ // we came to the limit, again ...
nNewGrowth = m_nMaximumResize;
if (nNewGrowth + nCurrentLength < m_nSize + nLen)
if (nNewGrowth + nCurrentLength < m_nSize + _rData.getLength())
// but it would not fit if we respect the limit
nNewGrowth = m_nSize + nLen - nCurrentLength;
nNewGrowth = m_nSize + _rData.getLength() - nCurrentLength;
}
nNewLength = nCurrentLength + nNewGrowth;
}
@ -204,29 +200,33 @@ void SAL_CALL OSequenceOutputStream::writeBytes( const sal_Int8* pStr, sal_Int32
m_rSequence.realloc(nNewLength);
}
OSL_ENSURE(m_rSequence.getLength() >= m_nSize + nLen,
OSL_ENSURE(m_rSequence.getLength() >= m_nSize + _rData.getLength(),
"ooops ... the realloc algorithm seems to be wrong :( !");
memcpy(m_rSequence.getArray() + m_nSize, pStr, nLen);
m_nSize += nLen;
memcpy(m_rSequence.getArray() + m_nSize, _rData.getConstArray(), _rData.getLength());
m_nSize += _rData.getLength();
}
void SAL_CALL OSequenceOutputStream::flush( ) throw(NotConnectedException, BufferSizeExceededException, IOException, RuntimeException, std::exception)
{
MutexGuard aGuard(m_aMutex);
if (!m_bConnected)
throw NotConnectedException();
// cut the sequence to the real size
m_rSequence.realloc(m_nSize);
// and next time write to the beginning
m_nSize = 0;
}
void SAL_CALL OSequenceOutputStream::closeOutput( ) throw(NotConnectedException, BufferSizeExceededException, IOException, RuntimeException, std::exception)
{
flush();
MutexGuard aGuard(m_aMutex);
if (!m_bConnected)
throw NotConnectedException();
// cut the sequence to the real size
m_rSequence.realloc(m_nSize);
// and don't allow any further accesses
m_bConnected = false;
}

View file

@ -74,21 +74,26 @@ public:
private:
inline sal_Int32 avail();
};
typedef ::cppu::WeakImplHelper1< ::com::sun::star::io::XOutputStream > OSequenceOutputStream_Base;
class COMPHELPER_DLLPUBLIC OSequenceOutputStream :
public ::cppu::WeakImplHelper1< ::com::sun::star::io::XOutputStream >
class OSequenceOutputStream : public OSequenceOutputStream_Base
{
protected:
::com::sun::star::uno::Sequence< sal_Int8 >& m_rSequence;
double m_nResizeFactor;
sal_Int32 m_nMinimumResize;
sal_Int32 m_nMaximumResize;
/** the size of the virtual stream. This is not the size of the sequence,
but the number of bytes written into the stream at a given moment.
*/
sal_Int32 m_nSize;
// the size of the virtual stream. This is not the size of the sequence, but the number of bytes written
// into the stream at a given moment.
bool m_bConnected; ///< closeOutput has been called ?
bool m_bConnected;
// closeOutput has been called ?
::osl::Mutex m_aMutex;
protected:
virtual ~OSequenceOutputStream() { if (m_bConnected) closeOutput(); }
public:
/** constructs the object. Everything written into the stream through the XOutputStream methods will be forwarded
@ -113,20 +118,13 @@ public:
sal_Int32 _nMaximumResize = -1
);
virtual ~OSequenceOutputStream() { if (m_bConnected) closeOutput(); }
sal_Int32 getSize() const { return m_nSize; }
/// same as XOutputStream::writeBytes (as expected :)
virtual void SAL_CALL writeBytes( const ::com::sun::star::uno::Sequence< sal_Int8 >& aData ) throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
void SAL_CALL writeBytes( const sal_Int8* pStr, sal_Int32 nLen )
throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException, std::exception);
/** Resizes the sequence used for writing to the really used size.
* Next time, writeBytes will write to the beginning of the sequence.
*/
/// this is a dummy in this implementation, no buffering is used
virtual void SAL_CALL flush( ) throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
/** Calls flush() and closes the output stream to prevent further manipulation with the sequence.
Every subsequent call to one of the XOutputStream methods will throw a <code>NotConnectedException</code>.
/** closes the output stream. In the case of this class, this means that the sequence used for writing is
resized to the really used size and not used any further, every subsequent call to one of the XOutputStream
methods will throw a <code>NotConnectedException</code>.
*/
virtual void SAL_CALL closeOutput( ) throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
};