include/vbahelper/vbahelper.hxx | 2 - include/vbahelper/vbashape.hxx | 2 - sot/source/sdstor/ucbstorage.cxx | 43 +++++++++++++++---------------- vbahelper/source/msforms/vbacombobox.cxx | 14 +++++----- vbahelper/source/msforms/vbacombobox.hxx | 3 +- vbahelper/source/msforms/vbalistbox.cxx | 14 +++++----- vbahelper/source/msforms/vbalistbox.hxx | 3 +- vbahelper/source/vbahelper/vbahelper.cxx | 18 ++++++------ vbahelper/source/vbahelper/vbashape.cxx | 24 ++++++++++------- 9 files changed, 65 insertions(+), 58 deletions(-)
New commits: commit d6ae28fe07497d217a53ee9062ddbf82766121a7 Author: Noel Grandin <noel.gran...@collabora.co.uk> AuthorDate: Tue Feb 28 09:48:21 2023 +0200 Commit: Noel Grandin <noel.gran...@collabora.co.uk> CommitDate: Tue Feb 28 10:53:47 2023 +0000 no need to allocate ucbhelper::Content separately in UCBStorage_Impl it is only one pointer big Change-Id: Id60710eca9a170733ebba4120359e03f384f9962 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/147945 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk> diff --git a/sot/source/sdstor/ucbstorage.cxx b/sot/source/sdstor/ucbstorage.cxx index 5b6ca1b72e11..e9857af608cd 100644 --- a/sot/source/sdstor/ucbstorage.cxx +++ b/sot/source/sdstor/ucbstorage.cxx @@ -459,7 +459,7 @@ public: OUString m_aURL; // the full path name to create the content OUString m_aContentType; OUString m_aOriginalContentType; - std::unique_ptr<::ucbhelper::Content> m_pContent; // the content that provides the storage elements + std::optional<::ucbhelper::Content> m_oContent; // the content that provides the storage elements std::unique_ptr<::utl::TempFileNamed> m_pTempFile; // temporary file, only for storages on stream SvStream* m_pSource; // original stream, only for storages on a stream ErrCode m_nError; @@ -498,9 +498,9 @@ public: void CreateContent(); ::ucbhelper::Content* GetContent() { - if ( !m_pContent ) + if ( !m_oContent ) CreateContent(); - return m_pContent.get(); + return m_oContent ? &*m_oContent : nullptr; } UCBStorageElementList_Impl& GetChildrenList() { @@ -1432,7 +1432,7 @@ UCBStorage::~UCBStorage() UCBStorage_Impl::UCBStorage_Impl( const ::ucbhelper::Content& rContent, const OUString& rName, StreamMode nMode, UCBStorage* pStorage, bool bDirect, bool bIsRoot, bool bIsRepair, Reference< XProgressHandler > const & xProgressHandler ) : m_pAntiImpl( pStorage ) - , m_pContent( new ::ucbhelper::Content( rContent ) ) + , m_oContent( rContent ) , m_pSource( nullptr ) //, m_pStream( NULL ) , m_nError( ERRCODE_NONE ) @@ -1556,10 +1556,10 @@ void UCBStorage_Impl::Init() // if the name was not already set to a temp name m_aName = aObj.GetLastName(); - if ( !m_pContent ) + if ( !m_oContent ) CreateContent(); - if ( m_pContent ) + if ( m_oContent ) { if ( m_bIsLinked ) { @@ -1602,7 +1602,7 @@ void UCBStorage_Impl::Init() { // get the manifest information from the package try { - Any aAny = m_pContent->getPropertyValue("MediaType"); + Any aAny = m_oContent->getPropertyValue("MediaType"); OUString aTmp; if ( ( aAny >>= aTmp ) && !aTmp.isEmpty() ) m_aContentType = m_aOriginalContentType = aTmp; @@ -1630,7 +1630,7 @@ void UCBStorage_Impl::Init() SotExchange::GetFormatDataFlavor( m_nFormat, aDataFlavor ); m_aUserTypeName = aDataFlavor.HumanPresentableName; - if( m_pContent && !m_bIsLinked && m_aClassId != SvGlobalName() ) + if( m_oContent && !m_bIsLinked && m_aClassId != SvGlobalName() ) ReadContent(); } @@ -1650,7 +1650,7 @@ void UCBStorage_Impl::CreateContent() aTemp += "?repairpackage"; } - m_pContent.reset(new ::ucbhelper::Content( aTemp, xComEnv, comphelper::getProcessComponentContext() )); + m_oContent.emplace( aTemp, xComEnv, comphelper::getProcessComponentContext() ); } catch (const ContentCreationException&) { @@ -1674,11 +1674,11 @@ void UCBStorage_Impl::ReadContent() try { GetContent(); - if ( !m_pContent ) + if ( !m_oContent ) return; // create cursor for access to children - Reference< XResultSet > xResultSet = m_pContent->createCursor( { "Title", "IsFolder", "MediaType", "Size" }, ::ucbhelper::INCLUDE_FOLDERS_AND_DOCUMENTS ); + Reference< XResultSet > xResultSet = m_oContent->createCursor( { "Title", "IsFolder", "MediaType", "Size" }, ::ucbhelper::INCLUDE_FOLDERS_AND_DOCUMENTS ); Reference< XRow > xRow( xResultSet, UNO_QUERY ); if ( xResultSet.is() ) { @@ -1907,7 +1907,7 @@ UCBStorage_Impl::~UCBStorage_Impl() { m_aChildrenList.clear(); - m_pContent.reset(); + m_oContent.reset(); m_pTempFile.reset(); } @@ -1941,7 +1941,7 @@ bool UCBStorage_Impl::Insert( ::ucbhelper::Content *pContent ) continue; // remove old content, create an "empty" new one and initialize it with the new inserted - m_pContent.reset(new ::ucbhelper::Content( aNewFolder )); + m_oContent.emplace( aNewFolder ); bRet = true; } } @@ -2016,7 +2016,8 @@ sal_Int16 UCBStorage_Impl::Commit() // - if storage is already inserted, and changed // - storage is not in a package // - it's a new storage, try to insert and commit if successful inserted - if ( !pElement->m_bIsInserted || m_bIsLinked || pElement->m_xStorage->Insert( m_pContent.get() ) ) + if ( !pElement->m_bIsInserted || m_bIsLinked + || pElement->m_xStorage->Insert( m_oContent ? &*m_oContent : nullptr ) ) { nLocalRet = pElement->m_xStorage->Commit(); pContent = pElement->GetContent(); @@ -2085,7 +2086,7 @@ sal_Int16 UCBStorage_Impl::Commit() return COMMIT_RESULT_FAILURE; } - if ( m_bIsRoot && m_pContent ) + if ( m_bIsRoot && m_oContent ) { // the root storage must flush the root package content if ( nRet == COMMIT_RESULT_SUCCESS ) @@ -2096,14 +2097,14 @@ sal_Int16 UCBStorage_Impl::Commit() // clipboard format and ClassId will be retrieved from the media type when the file is loaded again Any aType; aType <<= m_aContentType; - m_pContent->setPropertyValue("MediaType", aType ); + m_oContent->setPropertyValue("MediaType", aType ); if ( m_bIsLinked ) { // write a manifest file // first create a subfolder "META-inf" Content aNewSubFolder; - bool bRet = ::utl::UCBContentHelper::MakeFolder( *m_pContent, "META-INF", aNewSubFolder ); + bool bRet = ::utl::UCBContentHelper::MakeFolder( *m_oContent, "META-INF", aNewSubFolder ); if ( bRet ) { // create a stream to write the manifest file - use a temp file @@ -2140,7 +2141,7 @@ sal_Int16 UCBStorage_Impl::Commit() #endif // force writing Any aAny; - m_pContent->executeCommand( "flush", aAny ); + m_oContent->executeCommand( "flush", aAny ); if ( m_pSource != nullptr ) { std::unique_ptr<SvStream> pStream(::utl::UcbStreamHelper::CreateStream( m_pTempFile->GetURL(), StreamMode::STD_READ )); @@ -2682,8 +2683,8 @@ BaseStorage* UCBStorage::OpenStorage_Impl( const OUString& rEleName, StreamMode aFolderObj.removeSegment(); Content aFolder( aFolderObj.GetMainURL( INetURLObject::DecodeMechanism::NONE ), Reference < XCommandEnvironment >(), comphelper::getProcessComponentContext() ); - pImp->m_pContent.reset(new Content); - bool bRet = ::utl::UCBContentHelper::MakeFolder( aFolder, pImp->m_aName, *pImp->m_pContent ); + pImp->m_oContent.emplace(); + bool bRet = ::utl::UCBContentHelper::MakeFolder( aFolder, pImp->m_aName, *pImp->m_oContent ); if ( !bRet ) { SetError( SVSTREAM_CANNOT_MAKE ); @@ -2714,7 +2715,7 @@ UCBStorage_Impl* UCBStorage_Impl::OpenStorage( UCBStorageElement_Impl* pElement, if ( m_bIsLinked && !::utl::UCBContentHelper::Exists( aName ) ) { Content aNewFolder; - bool bRet = ::utl::UCBContentHelper::MakeFolder( *m_pContent, pElement->m_aOriginalName, aNewFolder ); + bool bRet = ::utl::UCBContentHelper::MakeFolder( *m_oContent, pElement->m_aOriginalName, aNewFolder ); if ( bRet ) pRet = new UCBStorage_Impl( aNewFolder, aName, nMode, nullptr, bDirect, false, m_bRepairPackage, m_xProgressHandler ); } commit d0b71f167cd4c03d574decb7b78ed1ecdab1c424 Author: Noel Grandin <noel.gran...@collabora.co.uk> AuthorDate: Tue Feb 28 09:46:27 2023 +0200 Commit: Noel Grandin <noel.gran...@collabora.co.uk> CommitDate: Tue Feb 28 10:53:39 2023 +0000 flatten some vba classes no need to allocate ShapeHelper separately, it is only one pointer big Change-Id: Ie4981ca81ac1dd430f22ba32357fcabbbd47bd09 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/147944 Tested-by: Noel Grandin <noel.gran...@collabora.co.uk> Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk> diff --git a/include/vbahelper/vbahelper.hxx b/include/vbahelper/vbahelper.hxx index 9be2b900a019..e9d8fa8bc01f 100644 --- a/include/vbahelper/vbahelper.hxx +++ b/include/vbahelper/vbahelper.hxx @@ -193,7 +193,7 @@ public: class VBAHELPER_DLLPUBLIC ConcreteXShapeGeometryAttributes final : public AbstractGeometryAttributes { - std::unique_ptr< ShapeHelper > m_pShapeHelper; + ShapeHelper m_aShapeHelper; public: ConcreteXShapeGeometryAttributes( const css::uno::Reference< css::drawing::XShape >& xShape ); virtual double getLeft() const override; diff --git a/include/vbahelper/vbashape.hxx b/include/vbahelper/vbashape.hxx index 11ac68780193..0766b275b556 100644 --- a/include/vbahelper/vbashape.hxx +++ b/include/vbahelper/vbashape.hxx @@ -60,7 +60,7 @@ typedef InheritedHelperInterfaceImpl< ListeningShape > ScVbaShape_BASE; class VBAHELPER_DLLPUBLIC ScVbaShape : public ScVbaShape_BASE { protected: - std::unique_ptr< ov::ShapeHelper > m_pShapeHelper; + ov::ShapeHelper m_aShapeHelper; css::uno::Reference< css::drawing::XShape > m_xShape; css::uno::Reference< css::drawing::XShapes > m_xShapes; css::uno::Reference< css::beans::XPropertySet > m_xPropertySet; diff --git a/vbahelper/source/msforms/vbacombobox.cxx b/vbahelper/source/msforms/vbacombobox.cxx index 16abb6d985d3..9f1d8dc81309 100644 --- a/vbahelper/source/msforms/vbacombobox.cxx +++ b/vbahelper/source/msforms/vbacombobox.cxx @@ -37,8 +37,8 @@ using namespace ooo::vba; ScVbaComboBox::ScVbaComboBox( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< uno::XInterface >& xControl, const uno::Reference< frame::XModel >& xModel, std::unique_ptr<ov::AbstractGeometryAttributes> pGeomHelper ) : ComboBoxImpl_BASE( xParent, xContext, xControl, xModel, std::move(pGeomHelper) ) + , maListHelper( m_xProps ) { - mpListHelper.reset( new ListControlHelper( m_xProps ) ); try { // grab the default value property name @@ -149,38 +149,38 @@ ScVbaComboBox::setText( const OUString& _text ) void SAL_CALL ScVbaComboBox::AddItem( const uno::Any& pvargItem, const uno::Any& pvargIndex ) { - mpListHelper->AddItem( pvargItem, pvargIndex ); + maListHelper.AddItem( pvargItem, pvargIndex ); } void SAL_CALL ScVbaComboBox::removeItem( const uno::Any& index ) { - mpListHelper->removeItem( index ); + maListHelper.removeItem( index ); } void SAL_CALL ScVbaComboBox::Clear( ) { - mpListHelper->Clear(); + maListHelper.Clear(); } void SAL_CALL ScVbaComboBox::setRowSource( const OUString& _rowsource ) { ScVbaControl::setRowSource( _rowsource ); - mpListHelper->setRowSource( _rowsource ); + maListHelper.setRowSource( _rowsource ); } sal_Int32 SAL_CALL ScVbaComboBox::getListCount() { - return mpListHelper->getListCount(); + return maListHelper.getListCount(); } uno::Any SAL_CALL ScVbaComboBox::List( const ::uno::Any& pvargIndex, const uno::Any& pvarColumn ) { - return mpListHelper->List( pvargIndex, pvarColumn ); + return maListHelper.List( pvargIndex, pvarColumn ); } sal_Int32 SAL_CALL ScVbaComboBox::getStyle() diff --git a/vbahelper/source/msforms/vbacombobox.hxx b/vbahelper/source/msforms/vbacombobox.hxx index feea8e52c504..4f682fc31648 100644 --- a/vbahelper/source/msforms/vbacombobox.hxx +++ b/vbahelper/source/msforms/vbacombobox.hxx @@ -19,6 +19,7 @@ #ifndef INCLUDED_VBAHELPER_SOURCE_MSFORMS_VBACOMBOBOX_HXX #define INCLUDED_VBAHELPER_SOURCE_MSFORMS_VBACOMBOBOX_HXX #include <memory> +#include <optional> #include <cppuhelper/implbase.hxx> #include <com/sun/star/uno/XComponentContext.hpp> #include <com/sun/star/beans/XPropertySet.hpp> @@ -33,7 +34,7 @@ typedef cppu::ImplInheritanceHelper<ScVbaControl, ov::msforms::XComboBox, css::script::XDefaultProperty > ComboBoxImpl_BASE; class ScVbaComboBox : public ComboBoxImpl_BASE { - std::unique_ptr< ListControlHelper > mpListHelper; + ListControlHelper maListHelper; OUString sSourceName; public: diff --git a/vbahelper/source/msforms/vbalistbox.cxx b/vbahelper/source/msforms/vbalistbox.cxx index 40e4445f675b..b7c1fc0097db 100644 --- a/vbahelper/source/msforms/vbalistbox.cxx +++ b/vbahelper/source/msforms/vbalistbox.cxx @@ -27,9 +27,9 @@ using namespace ooo::vba; ScVbaListBox::ScVbaListBox( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< css::uno::XInterface >& xControl, const uno::Reference< frame::XModel >& xModel, std::unique_ptr<ov::AbstractGeometryAttributes> pGeomHelper ) : ListBoxImpl_BASE(xParent, xContext, xControl, xModel, std::move(pGeomHelper)) + , maListHelper( m_xProps ) , m_nIndex(0) { - mpListHelper.reset( new ListControlHelper( m_xProps ) ); } // Attributes @@ -152,19 +152,19 @@ ScVbaListBox::Selected( sal_Int32 index ) void SAL_CALL ScVbaListBox::AddItem( const uno::Any& pvargItem, const uno::Any& pvargIndex ) { - mpListHelper->AddItem( pvargItem, pvargIndex ); + maListHelper.AddItem( pvargItem, pvargIndex ); } void SAL_CALL ScVbaListBox::removeItem( const uno::Any& index ) { - mpListHelper->removeItem( index ); + maListHelper.removeItem( index ); } void SAL_CALL ScVbaListBox::Clear( ) { - mpListHelper->Clear(); + maListHelper.Clear(); } // this is called when something like the following vba code is used @@ -236,19 +236,19 @@ void SAL_CALL ScVbaListBox::setRowSource( const OUString& _rowsource ) { ScVbaControl::setRowSource( _rowsource ); - mpListHelper->setRowSource( _rowsource ); + maListHelper.setRowSource( _rowsource ); } sal_Int32 SAL_CALL ScVbaListBox::getListCount() { - return mpListHelper->getListCount(); + return maListHelper.getListCount(); } uno::Any SAL_CALL ScVbaListBox::List( const ::uno::Any& pvargIndex, const uno::Any& pvarColumn ) { - return mpListHelper->List( pvargIndex, pvarColumn ); + return maListHelper.List( pvargIndex, pvarColumn ); } uno::Reference< msforms::XNewFont > SAL_CALL ScVbaListBox::getFont() diff --git a/vbahelper/source/msforms/vbalistbox.hxx b/vbahelper/source/msforms/vbalistbox.hxx index b87f9e74f7dd..b5dde46ebad3 100644 --- a/vbahelper/source/msforms/vbalistbox.hxx +++ b/vbahelper/source/msforms/vbalistbox.hxx @@ -19,6 +19,7 @@ #ifndef INCLUDED_VBAHELPER_SOURCE_MSFORMS_VBALISTBOX_HXX #define INCLUDED_VBAHELPER_SOURCE_MSFORMS_VBALISTBOX_HXX #include <memory> +#include <optional> #include <cppuhelper/implbase.hxx> #include <com/sun/star/uno/XComponentContext.hpp> #include <com/sun/star/script/XDefaultProperty.hpp> @@ -34,7 +35,7 @@ typedef cppu::ImplInheritanceHelper<ScVbaControl, ov::msforms::XListBox, css::sc class ScVbaListBox : public ListBoxImpl_BASE ,public PropListener { - std::unique_ptr< ListControlHelper > mpListHelper; + ListControlHelper maListHelper; sal_Int16 m_nIndex; diff --git a/vbahelper/source/vbahelper/vbahelper.cxx b/vbahelper/source/vbahelper/vbahelper.cxx index 751cc8f24144..db59398763c0 100644 --- a/vbahelper/source/vbahelper/vbahelper.cxx +++ b/vbahelper/source/vbahelper/vbahelper.cxx @@ -625,8 +625,8 @@ double PixelsToPoints( const css::uno::Reference< css::awt::XDevice >& xDevice, } ConcreteXShapeGeometryAttributes::ConcreteXShapeGeometryAttributes( const css::uno::Reference< css::drawing::XShape >& xShape ) + : m_aShapeHelper( xShape ) { - m_pShapeHelper.reset( new ShapeHelper( xShape ) ); } ConcreteXShapeGeometryAttributes::~ConcreteXShapeGeometryAttributes() { @@ -935,36 +935,36 @@ void UserFormGeometryHelper::implSetSize( double fSize, bool bHeight, bool bOute double ConcreteXShapeGeometryAttributes::getLeft() const { - return m_pShapeHelper->getLeft(); + return m_aShapeHelper.getLeft(); } void ConcreteXShapeGeometryAttributes::setLeft( double nLeft ) { - m_pShapeHelper->setLeft( nLeft ); + m_aShapeHelper.setLeft( nLeft ); } double ConcreteXShapeGeometryAttributes::getTop() const { - return m_pShapeHelper->getTop(); + return m_aShapeHelper.getTop(); } void ConcreteXShapeGeometryAttributes::setTop( double nTop ) { - m_pShapeHelper->setTop( nTop ); + m_aShapeHelper.setTop( nTop ); } double ConcreteXShapeGeometryAttributes::getHeight() const { - return m_pShapeHelper->getHeight(); + return m_aShapeHelper.getHeight(); } void ConcreteXShapeGeometryAttributes::setHeight( double nHeight ) { - m_pShapeHelper->setHeight( nHeight ); + m_aShapeHelper.setHeight( nHeight ); } double ConcreteXShapeGeometryAttributes::getWidth() const { - return m_pShapeHelper->getWidth(); + return m_aShapeHelper.getWidth(); } void ConcreteXShapeGeometryAttributes::setWidth( double nWidth) { - m_pShapeHelper->setWidth( nWidth ); + m_aShapeHelper.setWidth( nWidth ); } diff --git a/vbahelper/source/vbahelper/vbashape.cxx b/vbahelper/source/vbahelper/vbashape.cxx index fead96292774..165d8d206dd0 100644 --- a/vbahelper/source/vbahelper/vbashape.cxx +++ b/vbahelper/source/vbahelper/vbashape.cxx @@ -50,10 +50,14 @@ using namespace ::ooo::vba; using namespace ::com::sun::star; ScVbaShape::ScVbaShape( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, uno::Reference< drawing::XShape > xShape, uno::Reference< drawing::XShapes > xShapes, uno::Reference< frame::XModel > xModel, sal_Int32 nType ) - : ScVbaShape_BASE( xParent, xContext ), m_xShape(std::move( xShape )), m_xShapes(std::move( xShapes )), m_nType( nType ), m_xModel(std::move( xModel )) + : ScVbaShape_BASE( xParent, xContext ) + , m_aShapeHelper( xShape ) + , m_xShape(std::move( xShape )) + , m_xShapes(std::move( xShapes )) + , m_nType( nType ) + , m_xModel(std::move( xModel )) { m_xPropertySet.set( m_xShape, uno::UNO_QUERY_THROW ); - m_pShapeHelper.reset( new ShapeHelper( m_xShape ) ); addListeners(); } @@ -232,25 +236,25 @@ ScVbaShape::setAlternativeText( const OUString& sAltText ) double SAL_CALL ScVbaShape::getHeight() { - return m_pShapeHelper->getHeight(); + return m_aShapeHelper.getHeight(); } void SAL_CALL ScVbaShape::setHeight(double _height) { - m_pShapeHelper->setHeight( _height ); + m_aShapeHelper.setHeight( _height ); } double SAL_CALL ScVbaShape::getWidth() { - return m_pShapeHelper->getWidth(); + return m_aShapeHelper.getWidth(); } void SAL_CALL ScVbaShape::setWidth(double _width) { - m_pShapeHelper->setWidth( _width ); + m_aShapeHelper.setWidth( _width ); } double SAL_CALL @@ -259,7 +263,7 @@ ScVbaShape::getLeft() double left = 0; try { - left = m_pShapeHelper->getLeft(); + left = m_aShapeHelper.getLeft(); } catch( uno::Exception& ) { @@ -276,7 +280,7 @@ ScVbaShape::setLeft( double _left ) { try { - m_pShapeHelper->setLeft( _left ); + m_aShapeHelper.setLeft( _left ); } catch( uno::Exception& ) { @@ -291,7 +295,7 @@ ScVbaShape::getTop() double top = 0; try { - top = m_pShapeHelper->getTop(); + top = m_aShapeHelper.getTop(); } catch( uno::Exception& ) { @@ -307,7 +311,7 @@ ScVbaShape::setTop( double _top ) { try { - m_pShapeHelper->setTop( _top ); + m_aShapeHelper.setTop( _top ); } catch( uno::Exception& ) {