From 364cdd314fb4d6168990a469bfb10fc935dfc649 Mon Sep 17 00:00:00 2001 From: Luboš Luňák Date: Fri, 20 Dec 2019 11:40:59 +0100 Subject: use boost::shared_ptr for allocating an array MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Using make_shared() results in just one allocation instead of having one for the data and one for the shared_ptr's control block. But std::shared_ptr supports make_shared() for arrays only in C++20. Change-Id: If2d1223ebcc54ccfdccb15601d69a3563bd4f6c0 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/85589 Tested-by: Jenkins Reviewed-by: Luboš Luňák --- vcl/inc/skia/salbmp.hxx | 4 +++- vcl/skia/salbmp.cxx | 12 ++++++------ 2 files changed, 9 insertions(+), 7 deletions(-) (limited to 'vcl') diff --git a/vcl/inc/skia/salbmp.hxx b/vcl/inc/skia/salbmp.hxx index 78b864104a2c..40cbb62104d1 100644 --- a/vcl/inc/skia/salbmp.hxx +++ b/vcl/inc/skia/salbmp.hxx @@ -24,6 +24,8 @@ #include +#include + class VCL_PLUGIN_PUBLIC SkiaSalBitmap final : public SalBitmap { public: @@ -114,7 +116,7 @@ private: // mBitmap/mBuffer must be filled from it on demand if necessary by EnsureBitmapData(). SkBitmap mBitmap; sk_sp mImage; // possibly GPU-backed - std::shared_ptr mBuffer; + boost::shared_ptr mBuffer; int mScanlineSize; // size of one row in mBuffer sk_sp mAlphaImage; // cached contents as alpha image, possibly GPU-backed #ifdef DBG_UTIL diff --git a/vcl/skia/salbmp.cxx b/vcl/skia/salbmp.cxx index 4430d7f672cd..172b7c37ef92 100644 --- a/vcl/skia/salbmp.cxx +++ b/vcl/skia/salbmp.cxx @@ -21,6 +21,7 @@ #include #include +#include #include #include @@ -140,22 +141,21 @@ bool SkiaSalBitmap::CreateBitmapData() return false; } mScanlineSize = AlignedWidth4Bytes(bitScanlineWidth); - sal_uInt8* buffer = nullptr; if (mScanlineSize != 0 && mSize.Height() != 0) { size_t allocate = mScanlineSize * mSize.Height(); #ifdef DBG_UTIL allocate += sizeof(CANARY); #endif - buffer = new sal_uInt8[allocate]; + mBuffer = boost::make_shared(allocate); #ifdef DBG_UTIL // fill with random garbage + sal_uInt8* buffer = mBuffer.get(); for (size_t i = 0; i < allocate; i++) buffer[i] = (i & 0xFF); memcpy(buffer + allocate - sizeof(CANARY), CANARY, sizeof(CANARY)); #endif } - mBuffer.reset(buffer); } return true; } @@ -613,9 +613,9 @@ void SkiaSalBitmap::EnsureBitmapUniqueData() assert(memcmp(mBuffer.get() + allocate, CANARY, sizeof(CANARY)) == 0); allocate += sizeof(CANARY); #endif - sal_uInt8* newBuffer = new sal_uInt8[allocate]; - memcpy(newBuffer, mBuffer.get(), allocate); - mBuffer.reset(newBuffer); + boost::shared_ptr newBuffer = boost::make_shared(allocate); + memcpy(newBuffer.get(), mBuffer.get(), allocate); + mBuffer = newBuffer; } } -- cgit