comphelper/source/xml/attributelist.cxx | 70 ++------------------------------ include/comphelper/attributelist.hxx | 40 ++++++++++++++---- vcl/inc/unx/gtk/gtksalmenu.hxx | 2 vcl/unx/gtk/gtksalmenu.cxx | 25 ++++++++--- 4 files changed, 58 insertions(+), 79 deletions(-)
New commits: commit 9eae555542ce01cb289b9e736454abcf835b8394 Author: Noel Grandin <noel.gran...@collabora.co.uk> AuthorDate: Sun Apr 28 09:54:42 2019 +0200 Commit: Noel Grandin <noel.gran...@collabora.co.uk> CommitDate: Mon Apr 29 08:30:26 2019 +0200 speed up gtk menu construction at startup Change-Id: Ia28b1f0281485691e3b4188d23947014c1eff385 Reviewed-on: https://gerrit.libreoffice.org/71465 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk> diff --git a/vcl/inc/unx/gtk/gtksalmenu.hxx b/vcl/inc/unx/gtk/gtksalmenu.hxx index bdacee7ca178..b973684b21f1 100644 --- a/vcl/inc/unx/gtk/gtksalmenu.hxx +++ b/vcl/inc/unx/gtk/gtksalmenu.hxx @@ -59,6 +59,8 @@ private: bool mbNeedsUpdate; bool mbReturnFocusToDocument; bool mbAddedGrab; + /// Even setting null icon on a menuitem can be expensive, so cache state to avoid that call + bool mbHasNullItemIcon = true; GtkWidget* mpMenuBarContainerWidget; std::unique_ptr<utl::TempFile> mxPersonaImage; BitmapEx maPersonaBitmap; diff --git a/vcl/unx/gtk/gtksalmenu.cxx b/vcl/unx/gtk/gtksalmenu.cxx index 2f85e0710043..e3d9dc85c087 100644 --- a/vcl/unx/gtk/gtksalmenu.cxx +++ b/vcl/unx/gtk/gtksalmenu.cxx @@ -1063,6 +1063,9 @@ namespace void GtkSalMenu::NativeSetItemIcon( unsigned nSection, unsigned nItemPos, const Image& rImage ) { #if GLIB_CHECK_VERSION(2,38,0) + if (!!rImage && mbHasNullItemIcon) + return; + SolarMutexGuard aGuard; if (!!rImage) @@ -1081,9 +1084,13 @@ void GtkSalMenu::NativeSetItemIcon( unsigned nSection, unsigned nItemPos, const g_lo_menu_set_icon_to_item_in_section( G_LO_MENU( mpMenuModel ), nSection, nItemPos, pIcon ); g_object_unref(pIcon); g_bytes_unref(pBytes); + mbHasNullItemIcon = false; } else + { g_lo_menu_set_icon_to_item_in_section( G_LO_MENU( mpMenuModel ), nSection, nItemPos, nullptr ); + mbHasNullItemIcon = true; + } #else (void)nSection; (void)nItemPos; @@ -1222,12 +1229,18 @@ void GtkSalMenu::ActivateAllSubmenus(Menu* pMenuBar) { if ( pSalItem->mpSubMenu != nullptr ) { - pSalItem->mpSubMenu->mbInActivateCallback = true; - pMenuBar->HandleMenuActivateEvent(pSalItem->mpSubMenu->GetMenu()); - pSalItem->mpSubMenu->mbInActivateCallback = false; - pSalItem->mpSubMenu->ActivateAllSubmenus(pMenuBar); - pSalItem->mpSubMenu->Update(); - pMenuBar->HandleMenuDeActivateEvent(pSalItem->mpSubMenu->GetMenu()); + // We can re-enter this method via the new event loop that gets created + // in GtkClipboardTransferable::getTransferDataFlavorsAsVector, so use the InActivateCallback + // flag to detect that and skip some startup work. + if (!pSalItem->mpSubMenu->mbInActivateCallback) + { + pSalItem->mpSubMenu->mbInActivateCallback = true; + pMenuBar->HandleMenuActivateEvent(pSalItem->mpSubMenu->GetMenu()); + pSalItem->mpSubMenu->mbInActivateCallback = false; + pSalItem->mpSubMenu->ActivateAllSubmenus(pMenuBar); + pSalItem->mpSubMenu->Update(); + pMenuBar->HandleMenuDeActivateEvent(pSalItem->mpSubMenu->GetMenu()); + } } } } commit 8647288180806f8515bf2548db7280cbc657eaf3 Author: Noel Grandin <noel.gran...@collabora.co.uk> AuthorDate: Sat Apr 27 09:44:15 2019 +0200 Commit: Noel Grandin <noel.gran...@collabora.co.uk> CommitDate: Mon Apr 29 08:30:17 2019 +0200 optimise comphelper::AttributeList a little Change-Id: I48cb0a1b5dfcf6471c1cdf9d79445281f9f33020 Reviewed-on: https://gerrit.libreoffice.org/71463 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk> diff --git a/comphelper/source/xml/attributelist.cxx b/comphelper/source/xml/attributelist.cxx index 6c1578defd8f..fa918d01da29 100644 --- a/comphelper/source/xml/attributelist.cxx +++ b/comphelper/source/xml/attributelist.cxx @@ -27,57 +27,9 @@ using namespace com::sun::star; namespace comphelper { -struct TagAttribute_Impl -{ - TagAttribute_Impl( const OUString &aName, const OUString &aType, - const OUString &aValue ) - { - sName = aName; - sType = aType; - sValue = aValue; - } - - OUString sName; - OUString sType; - OUString sValue; -}; - -struct AttributeList_Impl -{ - AttributeList_Impl() - { - // performance improvement during adding - vecAttribute.reserve(20); - } - std::vector<struct TagAttribute_Impl> vecAttribute; -}; - -sal_Int16 SAL_CALL AttributeList::getLength() -{ - return static_cast<sal_Int16>(m_pImpl->vecAttribute.size()); -} - -OUString SAL_CALL AttributeList::getNameByIndex(sal_Int16 i) -{ - return ( i < static_cast < sal_Int16 > (m_pImpl->vecAttribute.size()) ) ? m_pImpl->vecAttribute[i].sName : OUString(); -} - -OUString SAL_CALL AttributeList::getTypeByIndex(sal_Int16 i) -{ - if( i < static_cast < sal_Int16 > (m_pImpl->vecAttribute.size() ) ) { - return m_pImpl->vecAttribute[i].sType; - } - return OUString(); -} - -OUString SAL_CALL AttributeList::getValueByIndex(sal_Int16 i) -{ - return ( i < static_cast < sal_Int16 > (m_pImpl->vecAttribute.size() ) ) ? m_pImpl->vecAttribute[i].sValue : OUString(); -} - OUString SAL_CALL AttributeList::getTypeByName( const OUString& sName ) { - for (auto const& attribute : m_pImpl->vecAttribute) + for (auto const& attribute : mAttributes) { if( attribute.sName == sName ) { return attribute.sType; @@ -88,7 +40,7 @@ OUString SAL_CALL AttributeList::getTypeByName( const OUString& sName ) OUString SAL_CALL AttributeList::getValueByName(const OUString& sName) { - for (auto const& attribute : m_pImpl->vecAttribute) + for (auto const& attribute : mAttributes) { if( attribute.sName == sName ) { return attribute.sValue; @@ -98,34 +50,22 @@ OUString SAL_CALL AttributeList::getValueByName(const OUString& sName) } AttributeList::AttributeList() - : m_pImpl(new AttributeList_Impl) { + // performance improvement during adding + mAttributes.reserve(20); } AttributeList::AttributeList(const AttributeList &r) : cppu::WeakImplHelper<XAttributeList, XCloneable>(r) - , m_pImpl(new AttributeList_Impl) { - *m_pImpl = *(r.m_pImpl); + mAttributes = r.mAttributes; } AttributeList::~AttributeList() { } -void AttributeList::AddAttribute(const OUString &sName, - const OUString &sType, const OUString &sValue) -{ - m_pImpl->vecAttribute.emplace_back(sName, sType, sValue ); -} - -void AttributeList::Clear() -{ - m_pImpl->vecAttribute.clear(); -} - css::uno::Reference< css::util::XCloneable > AttributeList::createClone() - { AttributeList *p = new AttributeList( *this ); return css::uno::Reference< css::util::XCloneable > ( static_cast<css::util::XCloneable *>(p) ); diff --git a/include/comphelper/attributelist.hxx b/include/comphelper/attributelist.hxx index 91635a412765..8d9248fd57c2 100644 --- a/include/comphelper/attributelist.hxx +++ b/include/comphelper/attributelist.hxx @@ -23,6 +23,7 @@ #include <sal/config.h> #include <memory> +#include <vector> #include <com/sun/star/util/XCloneable.hpp> #include <com/sun/star/xml/sax/XAttributeList.hpp> @@ -32,12 +33,17 @@ namespace comphelper { -struct AttributeList_Impl; +struct TagAttribute +{ + OUString sName; + OUString sType; + OUString sValue; +}; class COMPHELPER_DLLPUBLIC AttributeList : public ::cppu::WeakImplHelper<css::xml::sax::XAttributeList, css::util::XCloneable> { - std::unique_ptr<AttributeList_Impl> m_pImpl; + std::vector<TagAttribute> mAttributes; public: AttributeList(); AttributeList(const AttributeList &r); @@ -45,15 +51,33 @@ public: virtual ~AttributeList() override; // methods that are not contained in any interface - void AddAttribute(const OUString &sName , const OUString &sType , const OUString &sValue); - void Clear(); + void AddAttribute(const OUString &sName , const OUString &sType , const OUString &sValue) + { + mAttributes.push_back({sName, sType, sValue}); + } + void Clear() + { + mAttributes.clear(); + } // css::xml::sax::XAttributeList - virtual sal_Int16 SAL_CALL getLength() override; - virtual OUString SAL_CALL getNameByIndex(sal_Int16 i) override; - virtual OUString SAL_CALL getTypeByIndex(sal_Int16 i) override; + virtual sal_Int16 SAL_CALL getLength() override + { + return static_cast<sal_Int16>(mAttributes.size()); + } + virtual OUString SAL_CALL getNameByIndex(sal_Int16 i) override + { + return mAttributes[i].sName; + } + virtual OUString SAL_CALL getTypeByIndex(sal_Int16 i) override + { + return mAttributes[i].sType; + } virtual OUString SAL_CALL getTypeByName(const OUString& aName) override; - virtual OUString SAL_CALL getValueByIndex(sal_Int16 i) override; + virtual OUString SAL_CALL getValueByIndex(sal_Int16 i) override + { + return mAttributes[i].sValue; + } virtual OUString SAL_CALL getValueByName(const OUString& aName) override; // css::util::XCloneable _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits