[Libreoffice-commits] core.git: include/tools tools/source
Caolán McNamara
caolanm at redhat.com
Mon Mar 13 20:19:45 UTC 2017
include/tools/stream.hxx | 1
tools/source/stream/stream.cxx | 66 +++++++++++------------------------------
2 files changed, 20 insertions(+), 47 deletions(-)
New commits:
commit ee555c835aac8e21f0a08e7c9d513182728a4cfe
Author: Caolán McNamara <caolanm at redhat.com>
Date: Mon Mar 13 16:30:52 2017 +0000
merge these similar buffer flushes together
adds an extra SVSTREAM_WRITE_ERROR check to some of them, otherwise
they're all the same
Change-Id: I2a4c766ff267a246a9f126fa9b7d557cfa2d66b0
Reviewed-on: https://gerrit.libreoffice.org/35144
Tested-by: Jenkins <ci at libreoffice.org>
Reviewed-by: Caolán McNamara <caolanm at redhat.com>
Tested-by: Caolán McNamara <caolanm at redhat.com>
diff --git a/include/tools/stream.hxx b/include/tools/stream.hxx
index 3a1843d..bd7f77b 100644
--- a/include/tools/stream.hxx
+++ b/include/tools/stream.hxx
@@ -188,6 +188,7 @@ protected:
virtual void FlushData();
virtual void SetSize(sal_uInt64 nSize);
+ void FlushBuffer(bool isConsistent);
void ClearError();
void ClearBuffer();
diff --git a/tools/source/stream/stream.cxx b/tools/source/stream/stream.cxx
index fa69f58..f838edb 100644
--- a/tools/source/stream/stream.cxx
+++ b/tools/source/stream/stream.cxx
@@ -1196,6 +1196,19 @@ SvStream& SvStream::WriteUniOrByteString( const OUString& rStr, rtl_TextEncoding
return *this;
}
+void SvStream::FlushBuffer(bool isConsistent)
+{
+ if (m_isDirty && isConsistent) // Does stream require a flush?
+ {
+ SeekPos(m_nBufFilePos);
+ if (m_nCryptMask)
+ CryptAndWriteBuffer(m_pRWBuf, m_nBufActualLen);
+ else if (PutData(m_pRWBuf, m_nBufActualLen) != m_nBufActualLen)
+ SetError(SVSTREAM_WRITE_ERROR);
+ m_isDirty = false;
+ }
+}
+
std::size_t SvStream::ReadBytes( void* pData, std::size_t nCount )
{
std::size_t nSaveCount = nCount;
@@ -1225,15 +1238,7 @@ std::size_t SvStream::ReadBytes( void* pData, std::size_t nCount )
}
else
{
- if (m_isDirty) // Does stream require a flush?
- {
- SeekPos(m_nBufFilePos);
- if (m_nCryptMask)
- CryptAndWriteBuffer(m_pRWBuf, m_nBufActualLen);
- else
- PutData(m_pRWBuf, m_nBufActualLen);
- m_isDirty = false;
- }
+ FlushBuffer(true);
// Does data block fit into buffer?
if (nCount > m_nBufSize)
@@ -1288,6 +1293,7 @@ std::size_t SvStream::WriteBytes( const void* pData, std::size_t nCount )
{
if( !nCount )
return 0;
+
if (!m_isWritable)
{
SetError( ERRCODE_IO_CANTWRITE );
@@ -1321,16 +1327,7 @@ std::size_t SvStream::WriteBytes( const void* pData, std::size_t nCount )
}
else
{
- // Does stream require flushing?
- if (m_isDirty)
- {
- SeekPos(m_nBufFilePos);
- if (m_nCryptMask)
- CryptAndWriteBuffer( m_pRWBuf, (std::size_t)m_nBufActualLen );
- else
- PutData( m_pRWBuf, m_nBufActualLen );
- m_isDirty = false;
- }
+ FlushBuffer(true);
// Does data block fit into buffer?
if (nCount > m_nBufSize)
@@ -1385,15 +1382,7 @@ sal_uInt64 SvStream::Seek(sal_uInt64 const nFilePos)
}
else
{
- if (m_isDirty && m_isConsistent)
- {
- SeekPos(m_nBufFilePos);
- if (m_nCryptMask)
- CryptAndWriteBuffer( m_pRWBuf, m_nBufActualLen );
- else
- PutData( m_pRWBuf, m_nBufActualLen );
- m_isDirty = false;
- }
+ FlushBuffer(m_isConsistent);
m_nBufActualLen = 0;
m_nBufActualPos = 0;
m_pBufPos = m_pRWBuf;
@@ -1416,31 +1405,14 @@ sal_uInt64 SvStream::remainingSize()
void SvStream::Flush()
{
- if (m_isDirty && m_isConsistent)
- {
- SeekPos(m_nBufFilePos);
- if (m_nCryptMask)
- CryptAndWriteBuffer( m_pRWBuf, (std::size_t)m_nBufActualLen );
- else
- if (PutData( m_pRWBuf, m_nBufActualLen ) != m_nBufActualLen)
- SetError( SVSTREAM_WRITE_ERROR );
- m_isDirty = false;
- }
+ FlushBuffer(m_isConsistent);
if (m_isWritable)
FlushData();
}
void SvStream::RefreshBuffer()
{
- if (m_isDirty && m_isConsistent)
- {
- SeekPos(m_nBufFilePos);
- if (m_nCryptMask)
- CryptAndWriteBuffer( m_pRWBuf, (std::size_t)m_nBufActualLen );
- else
- PutData( m_pRWBuf, m_nBufActualLen );
- m_isDirty = false;
- }
+ FlushBuffer(m_isConsistent);
SeekPos(m_nBufFilePos);
m_nBufActualLen = (sal_uInt16)GetData( m_pRWBuf, m_nBufSize );
if (m_nBufActualLen && m_nError == ERRCODE_IO_PENDING)
More information about the Libreoffice-commits
mailing list