filter/source/config/cache/basecontainer.cxx |    6 ----
 filter/source/config/cache/cacheitem.cxx     |   11 ++++++--
 filter/source/config/cache/cacheitem.hxx     |    2 -
 filter/source/config/cache/filtercache.cxx   |   36 +++++++++++++++++----------
 filter/source/config/cache/filtercache.hxx   |    7 ++---
 5 files changed, 37 insertions(+), 25 deletions(-)

New commits:
commit e6cca743556c2135d5e381cdbd883e937221eef9
Author:     Noel Grandin <[email protected]>
AuthorDate: Sat May 14 20:55:56 2022 +0200
Commit:     Noel Grandin <[email protected]>
CommitDate: Mon May 16 15:14:13 2022 +0200

    tdf#121740 elide temporary CacheItem object in BaseContainer::getByName
    
    shaves 2% off load time
    
    Change-Id: I91cc04916d77bc7ece1561462403067478a74bca
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/134345
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <[email protected]>

diff --git a/filter/source/config/cache/basecontainer.cxx 
b/filter/source/config/cache/basecontainer.cxx
index c288e88cd2c7..6f9491eeaac1 100644
--- a/filter/source/config/cache/basecontainer.cxx
+++ b/filter/source/config/cache/basecontainer.cxx
@@ -236,12 +236,10 @@ css::uno::Any SAL_CALL BaseContainer::getByName(const 
OUString& sItem)
     // SAFE ->
     osl::MutexGuard aLock(m_aMutex);
 
-    CacheItem aItem;
     try
     {
         FilterCache* pCache = impl_getWorkingCache();
-        aItem = pCache->getItem(m_eType, sItem);
-        pCache->addStatePropsToItem(m_eType, sItem, aItem); // add implicit 
props "Finalized"/"Mandatory"
+        aValue = pCache->getItemWithStateProps(m_eType, sItem);
     }
     catch(const css::container::NoSuchElementException&)
     {
@@ -250,10 +248,8 @@ css::uno::Any SAL_CALL BaseContainer::getByName(const 
OUString& sItem)
     catch(const css::uno::Exception&)
     {
         // TODO invalid cache!? How should it be handled right?
-        aItem.clear();
     }
 
-    aValue <<= aItem.getAsPackedPropertyValueList();
     // <- SAFE
 
     return aValue;
diff --git a/filter/source/config/cache/cacheitem.cxx 
b/filter/source/config/cache/cacheitem.cxx
index e39278c2048b..2c50df8578d3 100644
--- a/filter/source/config/cache/cacheitem.cxx
+++ b/filter/source/config/cache/cacheitem.cxx
@@ -83,12 +83,12 @@ void CacheItem::validateUINames(const OUString& sActLocale)
 }
 
 
-css::uno::Sequence< css::beans::PropertyValue > 
CacheItem::getAsPackedPropertyValueList()
+css::uno::Sequence< css::beans::PropertyValue > 
CacheItem::getAsPackedPropertyValueList(bool bFinalized, bool bMandatory) const
 {
     sal_Int32 c = static_cast<sal_Int32>(size());
     sal_Int32 i = 0;
 
-    css::uno::Sequence< css::beans::PropertyValue > lList(c);
+    css::uno::Sequence< css::beans::PropertyValue > lList(c+2);
     css::beans::PropertyValue*                      pList = lList.getArray();
 
     for (const_iterator pProp  = begin();
@@ -100,11 +100,18 @@ css::uno::Sequence< css::beans::PropertyValue > 
CacheItem::getAsPackedPropertyVa
 
         if (!rValue.hasValue())
             continue;
+        assert (rName != PROPNAME_FINALIZED && rName != PROPNAME_MANDATORY);
 
         pList[i].Name  = rName ;
         pList[i].Value = rValue;
         ++i;
     }
+    pList[i].Name  = PROPNAME_FINALIZED ;
+    pList[i].Value <<= bFinalized;
+    ++i;
+    pList[i].Name  = PROPNAME_MANDATORY ;
+    pList[i].Value <<= bMandatory;
+    ++i;
     lList.realloc(i);
 
     return lList;
diff --git a/filter/source/config/cache/cacheitem.hxx 
b/filter/source/config/cache/cacheitem.hxx
index 659d6e696201..965bf7a40126 100644
--- a/filter/source/config/cache/cacheitem.hxx
+++ b/filter/source/config/cache/cacheitem.hxx
@@ -118,7 +118,7 @@ class CacheItem : public ::comphelper::SequenceAsHashMap
                     as a list of all properties of this cacheitem,
                     where empty properties was removed.
          */
-        css::uno::Sequence< css::beans::PropertyValue > 
getAsPackedPropertyValueList();
+        css::uno::Sequence< css::beans::PropertyValue > 
getAsPackedPropertyValueList(bool bFinalized, bool bMandatory) const;
 };
 
 
diff --git a/filter/source/config/cache/filtercache.cxx 
b/filter/source/config/cache/filtercache.cxx
index f7ce4467a56d..3fcff8d22478 100644
--- a/filter/source/config/cache/filtercache.cxx
+++ b/filter/source/config/cache/filtercache.cxx
@@ -349,6 +349,15 @@ CacheItem FilterCache::getItem(      EItemType        
eType,
     // SAFE ->
     osl::MutexGuard aLock(m_aMutex);
 
+    CacheItem aItem = impl_getItem(eType, sItem);
+    // <- SAFE
+    return aItem;
+}
+
+
+CacheItem& FilterCache::impl_getItem(      EItemType        eType,
+                               const OUString& sItem)
+{
     // search for right list
     // An exception is thrown if "eType" is unknown.
     // => rList will be valid everytimes next line is reached.
@@ -389,7 +398,6 @@ CacheItem FilterCache::getItem(      EItemType        eType,
     }
 
     return pIt->second;
-    // <- SAFE
 }
 
 
@@ -450,13 +458,14 @@ void FilterCache::refreshItem(      EItemType        
eType,
 }
 
 
-void FilterCache::addStatePropsToItem(      EItemType        eType,
-                                      const OUString& sItem,
-                                            CacheItem&       rItem)
+css::uno::Any FilterCache::getItemWithStateProps(      EItemType        eType,
+                                      const OUString& sItem)
 {
     // SAFE ->
     osl::MutexGuard aLock(m_aMutex);
 
+    const CacheItem& rItem = impl_getItem(eType, sItem);
+
     // Note: Opening of the configuration layer throws some exceptions
     // if it failed. So we mustn't check any reference here...
     css::uno::Reference< css::container::XNameAccess > xPackage;
@@ -494,9 +503,8 @@ void FilterCache::addStatePropsToItem(      EItemType       
 eType,
                     (sItem == sDefaultFrameLoader   )
                    )
                 {
-                    rItem[PROPNAME_FINALIZED] <<= true;
-                    rItem[PROPNAME_MANDATORY] <<= true;
-                    return;
+                    css::uno::Sequence aProps = 
rItem.getAsPackedPropertyValueList(true, true);
+                    return css::uno::Any(aProps);
                 }
                 /* <-- HACK */
 
@@ -514,17 +522,16 @@ void FilterCache::addStatePropsToItem(      EItemType     
   eType,
         default: break;
     }
 
+    bool bFinalized, bMandatory;
     try
     {
         css::uno::Reference< css::beans::XProperty > xItem;
         xSet->getByName(sItem) >>= xItem;
         css::beans::Property aDescription = xItem->getAsProperty();
 
-        bool bFinalized = ((aDescription.Attributes & 
css::beans::PropertyAttribute::READONLY  ) == 
css::beans::PropertyAttribute::READONLY  );
-        bool bMandatory = ((aDescription.Attributes & 
css::beans::PropertyAttribute::REMOVABLE) != 
css::beans::PropertyAttribute::REMOVABLE);
+        bFinalized = ((aDescription.Attributes & 
css::beans::PropertyAttribute::READONLY  ) == 
css::beans::PropertyAttribute::READONLY  );
+        bMandatory = ((aDescription.Attributes & 
css::beans::PropertyAttribute::REMOVABLE) != 
css::beans::PropertyAttribute::REMOVABLE);
 
-        rItem[PROPNAME_FINALIZED] <<= bFinalized;
-        rItem[PROPNAME_MANDATORY] <<= bMandatory;
     }
     catch(const css::container::NoSuchElementException&)
     {
@@ -537,10 +544,13 @@ void FilterCache::addStatePropsToItem(      EItemType     
   eType,
 
             => mark item as FINALIZED / MANDATORY, we don't support writing to 
the old format
         */
-        rItem[PROPNAME_FINALIZED] <<= true;
-        rItem[PROPNAME_MANDATORY] <<= true;
+        bFinalized = true;
+        bMandatory = true;
     }
 
+    css::uno::Sequence<css::beans::PropertyValue> aProps = 
rItem.getAsPackedPropertyValueList(bFinalized, bMandatory);
+
+    return css::uno::Any(aProps);
     // <- SAFE
 }
 
diff --git a/filter/source/config/cache/filtercache.hxx 
b/filter/source/config/cache/filtercache.hxx
index 526ce85d6126..8cb34701cc2a 100644
--- a/filter/source/config/cache/filtercache.hxx
+++ b/filter/source/config/cache/filtercache.hxx
@@ -524,10 +524,8 @@ class FilterCache : public cppu::BaseMutex
                         was not migrated to the new one. So we can't provide 
write access
                         to such items...
          */
-        void addStatePropsToItem(      EItemType        eType,
-                                         const OUString& sItem,
-                                               CacheItem&       rItem);
-
+        css::uno::Any getItemWithStateProps( EItemType        eType,
+                                             const OUString& sItem);
 
         /** TODO document me
 
@@ -600,6 +598,7 @@ class FilterCache : public cppu::BaseMutex
 
         CacheItemList& impl_getItemList(EItemType eType);
 
+        CacheItem& impl_getItem( EItemType eType, const OUString& sItem);
 
         /** @short      return a valid configuration update access
                         to the underlying configuration package, which

Reply via email to