summaryrefslogtreecommitdiff
path: root/comphelper
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2022-05-29 16:54:24 +0200
committerStephan Bergmann <sbergman@redhat.com>2022-05-29 18:38:07 +0200
commit3ca1a169e571a829598a00a2ffef6e1018d2cb18 (patch)
tree66c1ef5cc9cdb2823a3a5ca602a6c408918832b6 /comphelper
parentc3e9eb997f409f7fcf42659adedff43a8ade913d (diff)
Use boost::noinit_adaptor
Change-Id: Ide5f0394172548ed6a1ef4a6277ebf4752e685bb Reviewed-on: https://gerrit.libreoffice.org/c/core/+/135094 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
Diffstat (limited to 'comphelper')
-rw-r--r--comphelper/source/streaming/memorystream.cxx29
1 files changed, 10 insertions, 19 deletions
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;
}