summaryrefslogtreecommitdiff
path: root/comphelper
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2022-05-20 12:52:13 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2022-05-20 20:55:54 +0200
commit826b536fddfebf9e19efae9dbf3dbd86861c6d74 (patch)
treea7eaf5d330f0e1632e7bb249af8a59cd08e0b6c6 /comphelper
parent6510cbc486867db25d1d772f4a3b0b7b9bb2fc08 (diff)
don't waste time on memset when we're just going to overwrite it
Change-Id: Id01b056a28e23c55757b0b4e08a5901c76821b6b Reviewed-on: https://gerrit.libreoffice.org/c/core/+/134677 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'comphelper')
-rw-r--r--comphelper/source/streaming/memorystream.cxx21
1 files changed, 16 insertions, 5 deletions
diff --git a/comphelper/source/streaming/memorystream.cxx b/comphelper/source/streaming/memorystream.cxx
index a7612bf67b07..2abcb6b1209f 100644
--- a/comphelper/source/streaming/memorystream.cxx
+++ b/comphelper/source/streaming/memorystream.cxx
@@ -82,7 +82,18 @@ public:
virtual void SAL_CALL truncate() override;
private:
- std::vector< sal_Int8 > maData;
+ // prevents std::vector from wasting time doing memset on data we are going to overwrite anyway
+ struct NoInitInt8
+ {
+ sal_Int8 value;
+ NoInitInt8() noexcept {
+ // do nothing
+ static_assert(sizeof(NoInitInt8) == sizeof(sal_Int8), "invalid size");
+ static_assert(alignof(NoInitInt8) == alignof(sal_Int8), "invalid alignment");
+ }
+ };
+
+ std::vector< NoInitInt8 > maData;
sal_Int32 mnCursor;
};
@@ -132,8 +143,8 @@ sal_Int32 SAL_CALL UNOMemoryStream::readBytes( Sequence< sal_Int8 >& aData, sal_
if( nBytesToRead )
{
- sal_Int8* pData = &(*maData.begin());
- sal_Int8* pCursor = &(pData[mnCursor]);
+ NoInitInt8* pData = &(*maData.begin());
+ NoInitInt8* pCursor = &(pData[mnCursor]);
memcpy( static_cast<void*>(aData.getArray()), static_cast<void*>(pCursor), nBytesToRead );
mnCursor += nBytesToRead;
@@ -205,8 +216,8 @@ 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 );
- sal_Int8* pData = &(*maData.begin());
- sal_Int8* pCursor = &(pData[mnCursor]);
+ NoInitInt8* pData = &(*maData.begin());
+ NoInitInt8* pCursor = &(pData[mnCursor]);
memcpy( pCursor, aData.getConstArray(), nBytesToWrite );
mnCursor += nBytesToWrite;