[Libreoffice-commits] core.git: io/source

Arkadiy Illarionov (via logerrit) logerrit at kemper.freedesktop.org
Sun Sep 1 00:05:59 UTC 2019


 io/source/TextInputStream/TextInputStream.cxx |   19 +++------
 io/source/stm/odata.cxx                       |   50 +++++++++-----------------
 io/source/stm/streamhelper.cxx                |   13 +++---
 3 files changed, 30 insertions(+), 52 deletions(-)

New commits:
commit 01837a85004a6f891a09c0a63ed7eff75d634827
Author:     Arkadiy Illarionov <qarkai at gmail.com>
AuthorDate: Sat Aug 31 17:40:19 2019 +0300
Commit:     Arkadiy Illarionov <qarkai at gmail.com>
CommitDate: Sun Sep 1 02:04:50 2019 +0200

    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 at collabora.com>
    Reviewed-by: Arkadiy Illarionov <qarkai at gmail.com>

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();
 }
 


More information about the Libreoffice-commits mailing list