comphelper/source/streaming/memorystream.cxx |   29 +++++++++------------------
 1 file changed, 10 insertions(+), 19 deletions(-)

New commits:
commit 3ca1a169e571a829598a00a2ffef6e1018d2cb18
Author:     Stephan Bergmann <sberg...@redhat.com>
AuthorDate: Sun May 29 16:54:24 2022 +0200
Commit:     Stephan Bergmann <sberg...@redhat.com>
CommitDate: Sun May 29 18:38:07 2022 +0200

    Use boost::noinit_adaptor
    
    Change-Id: Ide5f0394172548ed6a1ef4a6277ebf4752e685bb
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/135094
    Tested-by: Jenkins
    Reviewed-by: Stephan Bergmann <sberg...@redhat.com>

diff --git a/comphelper/source/streaming/memorystream.cxx 
b/comphelper/source/streaming/memorystream.cxx
index 199d6a9a6f77..2239bf8e4a93 100644
--- a/comphelper/source/streaming/memorystream.cxx
+++ b/comphelper/source/streaming/memorystream.cxx
@@ -18,6 +18,9 @@
  */
 
 #include <algorithm>
+#include <memory>
+
+#include <boost/core/noinit_adaptor.hpp>
 
 #include <com/sun/star/lang/IllegalArgumentException.hpp>
 #include <com/sun/star/lang/XServiceInfo.hpp>
@@ -92,18 +95,7 @@ public:
     virtual sal_Int32 writeSomeBytes(const sal_Int8* aData, sal_Int32 
nBytesToWrite) override;
 
 private:
-    // prevents std::vector from wasting time doing memset on data we are 
going to overwrite anyway
-    struct NoInitInt8
-    {
-        sal_Int8 value;
-        NoInitInt8() noexcept {
-            static_assert(sizeof(NoInitInt8) == sizeof(sal_Int8), "invalid 
size");
-            static_assert(alignof(NoInitInt8) == alignof(sal_Int8), "invalid 
alignment");
-            /* coverity[uninit_member] - deliberately do nothing to leave 
uninitialized */
-        }
-    };
-
-    std::vector< NoInitInt8 > maData;
+    std::vector< sal_Int8, boost::noinit_adaptor<std::allocator<sal_Int8>> > 
maData;
     sal_Int32 mnCursor;
 };
 
@@ -153,9 +145,9 @@ sal_Int32 SAL_CALL UNOMemoryStream::readBytes( Sequence< 
sal_Int8 >& aData, sal_
 
     if( nBytesToRead )
     {
-        NoInitInt8* pData = &(*maData.begin());
-        NoInitInt8* pCursor = &(pData[mnCursor]);
-        memcpy( static_cast<void*>(aData.getArray()), 
static_cast<void*>(pCursor), nBytesToRead );
+        sal_Int8* pData = &(*maData.begin());
+        sal_Int8* pCursor = &(pData[mnCursor]);
+        memcpy( aData.getArray(), static_cast<void*>(pCursor), nBytesToRead );
 
         mnCursor += nBytesToRead;
     }
@@ -226,10 +218,9 @@ void SAL_CALL UNOMemoryStream::writeBytes( const Sequence< 
sal_Int8 >& aData )
     if( static_cast< sal_Int32 >( nNewSize ) > static_cast< sal_Int32 >( 
maData.size() ) )
         maData.resize( nNewSize );
 
-    NoInitInt8* pData = &(*maData.begin());
-    NoInitInt8* pCursor = &(pData[mnCursor]);
-    // cast to avoid -Werror=class-memaccess
-    memcpy(static_cast<void*>(pCursor), aData.getConstArray(), nBytesToWrite);
+    sal_Int8* pData = &(*maData.begin());
+    sal_Int8* pCursor = &(pData[mnCursor]);
+    memcpy(pCursor, aData.getConstArray(), nBytesToWrite);
 
     mnCursor += nBytesToWrite;
 }

Reply via email to