summaryrefslogtreecommitdiffstats
path: root/io
diff options
context:
space:
mode:
authorArkadiy Illarionov <qarkai@gmail.com>2019-08-31 17:40:19 +0300
committerArkadiy Illarionov <qarkai@gmail.com>2019-09-01 02:04:50 +0200
commit01837a85004a6f891a09c0a63ed7eff75d634827 (patch)
tree91dc39c58bde987760ac55aae876e9ec578cda43 /io
parentdbaccess: delete old paste autoincrement logic (diff)
downloadcore-01837a85004a6f891a09c0a63ed7eff75d634827.tar.gz
core-01837a85004a6f891a09c0a63ed7eff75d634827.zip
Simplify Sequence iterations in io
Use comphelper::findValue and initializer lists. Change-Id: I4ebaf556a21b263e48b82a7290093eb8a832d9da Reviewed-on: https://gerrit.libreoffice.org/78351 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com> Reviewed-by: Arkadiy Illarionov <qarkai@gmail.com>
Diffstat (limited to 'io')
-rw-r--r--io/source/TextInputStream/TextInputStream.cxx19
-rw-r--r--io/source/stm/odata.cxx50
-rw-r--r--io/source/stm/streamhelper.cxx13
3 files changed, 30 insertions, 52 deletions
diff --git a/io/source/TextInputStream/TextInputStream.cxx b/io/source/TextInputStream/TextInputStream.cxx
index c1ae805571f6..d90f30976ec8 100644
--- a/io/source/TextInputStream/TextInputStream.cxx
+++ b/io/source/TextInputStream/TextInputStream.cxx
@@ -19,6 +19,7 @@
#include <string.h>
+#include <comphelper/sequence.hxx>
#include <cppuhelper/implbase.hxx>
#include <cppuhelper/supportsservice.hxx>
@@ -167,8 +168,6 @@ OUString OTextInputStream::implReadString( const Sequence< sal_Unicode >& Delimi
bool bFound = false;
bool bFoundFirstLineEndChar = false;
sal_Unicode cFirstLineEndChar = 0;
- const sal_Unicode* pDelims = Delimiters.getConstArray();
- const sal_Int32 nDelimCount = Delimiters.getLength();
while( !bFound )
{
// Still characters available?
@@ -213,18 +212,12 @@ OUString OTextInputStream::implReadString( const Sequence< sal_Unicode >& Delimi
cFirstLineEndChar = c;
}
}
- else
+ else if( comphelper::findValue(Delimiters, c) != -1 )
{
- for( sal_Int32 i = 0 ; i < nDelimCount ; i++ )
- {
- if( c == pDelims[ i ] )
- {
- bFound = true;
- nCopyLen = nBufferReadPos;
- if( bRemoveDelimiter )
- nCopyLen--;
- }
- }
+ bFound = true;
+ nCopyLen = nBufferReadPos;
+ if( bRemoveDelimiter )
+ nCopyLen--;
}
}
diff --git a/io/source/stm/odata.cxx b/io/source/stm/odata.cxx
index 260280216c11..0c1dd29f9bb1 100644
--- a/io/source/stm/odata.cxx
+++ b/io/source/stm/odata.cxx
@@ -167,7 +167,7 @@ sal_Int8 ODataInputStream::readByte()
{
throw UnexpectedEOFException();
}
- return aTmp.getArray()[0];
+ return aTmp.getConstArray()[0];
}
sal_Unicode ODataInputStream::readChar()
@@ -522,54 +522,40 @@ void ODataOutputStream::writeBoolean(sal_Bool Value)
void ODataOutputStream::writeByte(sal_Int8 Value)
{
- Sequence<sal_Int8> aTmp( 1 );
- aTmp.getArray()[0] = Value;
- writeBytes( aTmp );
+ writeBytes( { Value } );
}
void ODataOutputStream::writeChar(sal_Unicode Value)
{
- Sequence<sal_Int8> aTmp( 2 );
- sal_Int8 * pBytes = aTmp.getArray();
- pBytes[0] = sal_Int8(Value >> 8);
- pBytes[1] = sal_Int8(Value);
- writeBytes( aTmp );
+ writeBytes( { sal_Int8(Value >> 8),
+ sal_Int8(Value) } );
}
void ODataOutputStream::writeShort(sal_Int16 Value)
{
- Sequence<sal_Int8> aTmp( 2 );
- sal_Int8 * pBytes = aTmp.getArray();
- pBytes[0] = sal_Int8(Value >> 8);
- pBytes[1] = sal_Int8(Value);
- writeBytes( aTmp );
+ writeBytes( { sal_Int8(Value >> 8),
+ sal_Int8(Value) } );
}
void ODataOutputStream::writeLong(sal_Int32 Value)
{
- Sequence<sal_Int8> aTmp( 4 );
- sal_Int8 * pBytes = aTmp.getArray();
- pBytes[0] = sal_Int8(Value >> 24);
- pBytes[1] = sal_Int8(Value >> 16);
- pBytes[2] = sal_Int8(Value >> 8);
- pBytes[3] = sal_Int8(Value);
- writeBytes( aTmp );
+ writeBytes( { sal_Int8(Value >> 24),
+ sal_Int8(Value >> 16),
+ sal_Int8(Value >> 8),
+ sal_Int8(Value) } );
}
void ODataOutputStream::writeHyper(sal_Int64 Value)
{
- Sequence<sal_Int8> aTmp( 8 );
- sal_Int8 * pBytes = aTmp.getArray();
- pBytes[0] = sal_Int8(Value >> 56);
- pBytes[1] = sal_Int8(Value >> 48);
- pBytes[2] = sal_Int8(Value >> 40);
- pBytes[3] = sal_Int8(Value >> 32);
- pBytes[4] = sal_Int8(Value >> 24);
- pBytes[5] = sal_Int8(Value >> 16);
- pBytes[6] = sal_Int8(Value >> 8);
- pBytes[7] = sal_Int8(Value);
- writeBytes( aTmp );
+ writeBytes( { sal_Int8(Value >> 56),
+ sal_Int8(Value >> 48),
+ sal_Int8(Value >> 40),
+ sal_Int8(Value >> 32),
+ sal_Int8(Value >> 24),
+ sal_Int8(Value >> 16),
+ sal_Int8(Value >> 8),
+ sal_Int8(Value) } );
}
diff --git a/io/source/stm/streamhelper.cxx b/io/source/stm/streamhelper.cxx
index 20280b850563..be0644d5e1b2 100644
--- a/io/source/stm/streamhelper.cxx
+++ b/io/source/stm/streamhelper.cxx
@@ -118,7 +118,7 @@ void MemRingBuffer::readAt( sal_Int32 nPos, Sequence<sal_Int8> &seq , sal_Int32
void MemRingBuffer::writeAt( sal_Int32 nPos, const Sequence<sal_Int8> &seq )
{
checkInvariants();
- sal_Int32 nLen = seq.getLength();
+ const sal_Int32 nLen = seq.getLength();
if( nPos < 0 || nPos > std::numeric_limits< sal_Int32 >::max() - nLen )
{
@@ -127,7 +127,8 @@ void MemRingBuffer::writeAt( sal_Int32 nPos, const Sequence<sal_Int8> &seq )
}
if( nPos + nLen - m_nOccupiedBuffer > 0 ) {
- resizeBuffer( nPos + seq.getLength() );
+ resizeBuffer( nPos + nLen );
+ m_nOccupiedBuffer = nPos + nLen;
}
sal_Int32 nStartWritingIndex = m_nStart + nPos;
@@ -135,18 +136,16 @@ void MemRingBuffer::writeAt( sal_Int32 nPos, const Sequence<sal_Int8> &seq )
nStartWritingIndex -= m_nBufferLen;
}
- if( nLen + nStartWritingIndex > m_nBufferLen ) {
+ if( const sal_Int32 nBufferRestLen = m_nBufferLen-nStartWritingIndex; nLen > nBufferRestLen ) {
// two area copy
- memcpy( &(m_p[nStartWritingIndex]) , seq.getConstArray(), m_nBufferLen-nStartWritingIndex );
- memcpy( m_p , &( seq.getConstArray()[m_nBufferLen-nStartWritingIndex] ),
- nLen - (m_nBufferLen-nStartWritingIndex) );
+ memcpy( &(m_p[nStartWritingIndex]) , seq.getConstArray(), nBufferRestLen );
+ memcpy( m_p , &( seq.getConstArray()[nBufferRestLen] ), nLen - nBufferRestLen );
}
else {
// one area copy
memcpy( &( m_p[nStartWritingIndex]), seq.getConstArray() , nLen );
}
- m_nOccupiedBuffer = std::max( nPos + seq.getLength() , m_nOccupiedBuffer );
checkInvariants();
}