comphelper/source/container/enumhelper.cxx   |   31 ++++++++++++++++++++-------
 filter/source/config/cache/basecontainer.cxx |    5 +---
 filter/source/config/cache/filterfactory.cxx |    3 --
 include/comphelper/enumhelper.hxx            |   10 ++++++--
 4 files changed, 33 insertions(+), 16 deletions(-)

New commits:
commit e79db65efb48f2f4e82945fc850bc38c8923e22d
Author:     Noel Grandin <noel.gran...@collabora.co.uk>
AuthorDate: Wed May 25 09:28:16 2022 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Wed May 25 14:54:13 2022 +0200

    allow comphelper::OEnumerationByName to use a vector too for names
    
    so we can skip some allocation.
    Use a std::variant to preserve existing functionality
    
    Change-Id: If01ebb04f7895fd52fa3f5d90648868fd38dc39e
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/134929
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>

diff --git a/comphelper/source/container/enumhelper.cxx 
b/comphelper/source/container/enumhelper.cxx
index 2487d3adf234..b5fe864c8820 100644
--- a/comphelper/source/container/enumhelper.cxx
+++ b/comphelper/source/container/enumhelper.cxx
@@ -36,8 +36,8 @@ OEnumerationByName::OEnumerationByName(const 
css::uno::Reference<css::container:
 
 
 OEnumerationByName::OEnumerationByName(const 
css::uno::Reference<css::container::XNameAccess>& _rxAccess,
-                                       const css::uno::Sequence< OUString >&   
        _aNames  )
-    :m_aNames(_aNames)
+                                       std::vector<OUString> _aNames  )
+    :m_aNames(std::move(_aNames))
     ,m_xAccess(_rxAccess)
     ,m_nPos(0)
     ,m_bListening(false)
@@ -45,7 +45,6 @@ OEnumerationByName::OEnumerationByName(const 
css::uno::Reference<css::container:
     impl_startDisposeListening();
 }
 
-
 OEnumerationByName::~OEnumerationByName()
 {
     std::lock_guard aLock(m_aLock);
@@ -58,7 +57,7 @@ sal_Bool SAL_CALL OEnumerationByName::hasMoreElements(  )
 {
     std::lock_guard aLock(m_aLock);
 
-    if (m_xAccess.is() && m_aNames.getLength() > m_nPos)
+    if (m_xAccess.is() && getLength() > m_nPos)
         return true;
 
     if (m_xAccess.is())
@@ -76,10 +75,10 @@ css::uno::Any SAL_CALL OEnumerationByName::nextElement(  )
     std::lock_guard aLock(m_aLock);
 
     css::uno::Any aRes;
-    if (m_xAccess.is() && m_nPos < m_aNames.getLength())
-        aRes = m_xAccess->getByName(m_aNames.getConstArray()[m_nPos++]);
+    if (m_xAccess.is() && m_nPos < getLength())
+        aRes = m_xAccess->getByName(getElement(m_nPos++));
 
-    if (m_xAccess.is() && m_nPos >= m_aNames.getLength())
+    if (m_xAccess.is() && m_nPos >= getLength())
     {
         impl_stopDisposeListening();
         m_xAccess.clear();
@@ -91,7 +90,6 @@ css::uno::Any SAL_CALL OEnumerationByName::nextElement(  )
     return aRes;
 }
 
-
 void SAL_CALL OEnumerationByName::disposing(const css::lang::EventObject& 
aEvent)
 {
     std::lock_guard aLock(m_aLock);
@@ -132,6 +130,23 @@ void OEnumerationByName::impl_stopDisposeListening()
     osl_atomic_decrement(&m_refCount);
 }
 
+sal_Int32 OEnumerationByName::getLength() const
+{
+    if (m_aNames.index() == 0)
+        return std::get<css::uno::Sequence<OUString>>(m_aNames).getLength();
+    else
+        return std::get<std::vector<OUString>>(m_aNames).size();
+}
+
+const OUString& OEnumerationByName::getElement(sal_Int32 nIndex) const
+{
+    if (m_aNames.index() == 0)
+        return 
std::get<css::uno::Sequence<OUString>>(m_aNames).getConstArray()[nIndex];
+    else
+        return std::get<std::vector<OUString>>(m_aNames)[nIndex];
+}
+
+
 OEnumerationByIndex::OEnumerationByIndex(const css::uno::Reference< 
css::container::XIndexAccess >& _rxAccess)
     :m_xAccess(_rxAccess)
     ,m_nPos(0)
diff --git a/filter/source/config/cache/basecontainer.cxx 
b/filter/source/config/cache/basecontainer.cxx
index dbbb9bcc23da..0dee9d4ba25a 100644
--- a/filter/source/config/cache/basecontainer.cxx
+++ b/filter/source/config/cache/basecontainer.cxx
@@ -344,7 +344,7 @@ css::uno::Reference< css::container::XEnumeration > 
SAL_CALL BaseContainer::crea
 {
     OSL_FAIL("not pure virtual ... but not really implemented .-)");
 
-    return new ::comphelper::OEnumerationByName(this, css::uno::Sequence< 
OUString >());
+    return new ::comphelper::OEnumerationByName(this, {});
 }
 
 
@@ -383,8 +383,7 @@ css::uno::Reference< css::container::XEnumeration > 
SAL_CALL BaseContainer::crea
              Further its easier to work directly with the return value
              instead of checking of NULL returns! */
 
-    css::uno::Sequence< OUString > lSubSet = 
comphelper::containerToSequence(lKeys);
-    return new ::comphelper::OEnumerationByName(this, lSubSet);
+    return new ::comphelper::OEnumerationByName(this, std::move(lKeys));
 }
 
 
diff --git a/filter/source/config/cache/filterfactory.cxx 
b/filter/source/config/cache/filterfactory.cxx
index 54225db86d7c..e16ac3a2678d 100644
--- a/filter/source/config/cache/filterfactory.cxx
+++ b/filter/source/config/cache/filterfactory.cxx
@@ -185,8 +185,7 @@ css::uno::Reference< css::container::XEnumeration > 
SAL_CALL FilterFactory::crea
     // pack list of item names as an enum list
     // Attention: Do not return empty reference for empty list!
     // The outside check "hasMoreElements()" should be enough, to detect this 
state :-)
-    css::uno::Sequence< OUString > lSet = 
comphelper::containerToSequence(lEnumSet);
-    return new ::comphelper::OEnumerationByName(this, lSet);
+    return new ::comphelper::OEnumerationByName(this, std::move(lEnumSet));
 }
 
 
diff --git a/include/comphelper/enumhelper.hxx 
b/include/comphelper/enumhelper.hxx
index 52f3aa743ade..cf89e90fe11d 100644
--- a/include/comphelper/enumhelper.hxx
+++ b/include/comphelper/enumhelper.hxx
@@ -22,9 +22,11 @@
 
 #include <com/sun/star/container/XEnumeration.hpp>
 #include <com/sun/star/lang/XEventListener.hpp>
+#include <comphelper/comphelperdllapi.h>
 #include <cppuhelper/implbase.hxx>
 #include <mutex>
-#include <comphelper/comphelperdllapi.h>
+#include <variant>
+#include <vector>
 
 namespace com::sun::star::container { class XIndexAccess; }
 namespace com::sun::star::container { class XNameAccess; }
@@ -39,7 +41,7 @@ class COMPHELPER_DLLPUBLIC OEnumerationByName final :
                          public ::cppu::WeakImplHelper< 
css::container::XEnumeration ,
                                                           
css::lang::XEventListener    >
 {
-    css::uno::Sequence< OUString > const                m_aNames;
+    std::variant<css::uno::Sequence< OUString >, std::vector<OUString>> 
m_aNames;
     css::uno::Reference< css::container::XNameAccess >  m_xAccess;
     sal_Int32                                           m_nPos;
     bool                                                m_bListening;
@@ -48,7 +50,7 @@ class COMPHELPER_DLLPUBLIC OEnumerationByName final :
 public:
     OEnumerationByName(const css::uno::Reference< css::container::XNameAccess 
>& _rxAccess);
     OEnumerationByName(const css::uno::Reference< css::container::XNameAccess 
>& _rxAccess,
-                       const css::uno::Sequence< OUString >&             
_aNames  );
+                       std::vector<OUString>             _aNames  );
     virtual ~OEnumerationByName() override;
 
     virtual sal_Bool SAL_CALL hasMoreElements(  ) override;
@@ -57,6 +59,8 @@ public:
     virtual void SAL_CALL disposing(const css::lang::EventObject& aEvent) 
override;
 
 private:
+    sal_Int32 getLength() const;
+    const OUString& getElement(sal_Int32 nIndex) const;
     COMPHELPER_DLLPRIVATE void impl_startDisposeListening();
     COMPHELPER_DLLPRIVATE void impl_stopDisposeListening();
 };

Reply via email to