summaryrefslogtreecommitdiff
path: root/comphelper
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2022-05-25 09:28:16 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2022-05-25 14:54:13 +0200
commite79db65efb48f2f4e82945fc850bc38c8923e22d (patch)
tree7ba6b5b58ca3a0169aa5d03ec101c83e6be241c4 /comphelper
parent3866b859ee715da9eb124bc6fa8d2193d6af2442 (diff)
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.grandin@collabora.co.uk>
Diffstat (limited to 'comphelper')
-rw-r--r--comphelper/source/container/enumhelper.cxx31
1 files changed, 23 insertions, 8 deletions
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)