[Libreoffice-commits] core.git: Branch 'distro/cib/libreoffice-6-1' - include/toolkit toolkit/source
Samuel Mehrbrodt (via logerrit)
logerrit at kemper.freedesktop.org
Fri May 1 15:48:08 UTC 2020
include/toolkit/controls/eventcontainer.hxx | 16 +++++++-
toolkit/source/controls/eventcontainer.cxx | 56 +++++++++++++++++++---------
2 files changed, 52 insertions(+), 20 deletions(-)
New commits:
commit 872ee053d3c75ca47fbd29f4504d1bd5c21b05df
Author: Samuel Mehrbrodt <Samuel.Mehrbrodt at cib.de>
AuthorDate: Thu Apr 30 14:24:06 2020 +0200
Commit: Thorsten Behrens <Thorsten.Behrens at CIB.de>
CommitDate: Fri May 1 17:47:35 2020 +0200
Revert "remove some "optimisation" insanity in ScriptEventContainer"
This broke the event order in basic dialog xml,
which in turn broke macro signatures.
This reverts commit 85f08e3e34bea01456eaf8989ac4f77d3900d5c5.
Change-Id: I49ef2eb200571a0fd862770abc4331b6ea053e2b
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/93209
Tested-by: Thorsten Behrens <Thorsten.Behrens at CIB.de>
Reviewed-by: Thorsten Behrens <Thorsten.Behrens at CIB.de>
diff --git a/include/toolkit/controls/eventcontainer.hxx b/include/toolkit/controls/eventcontainer.hxx
index 65d0418bdc27..aba5ce9f3aa4 100644
--- a/include/toolkit/controls/eventcontainer.hxx
+++ b/include/toolkit/controls/eventcontainer.hxx
@@ -32,12 +32,24 @@
namespace toolkit
{
+// Hashtable to optimize
+typedef std::unordered_map
+<
+ OUString,
+ sal_Int32,
+ OUStringHash
+>
+NameContainerNameMap;
+
+
class ScriptEventContainer : public ::cppu::WeakImplHelper<
css::container::XNameContainer,
css::container::XContainer >
{
- std::unordered_map< OUString, css::uno::Any>
- mHashMap;
+ NameContainerNameMap mHashMap;
+ css::uno::Sequence< OUString > mNames;
+ std::vector< css::uno::Any > mValues;
+ sal_Int32 mnElementCount;
css::uno::Type mType;
ContainerListenerMultiplexer maContainerListeners;
diff --git a/toolkit/source/controls/eventcontainer.cxx b/toolkit/source/controls/eventcontainer.cxx
index 8873c638ad0a..b64b9a80d404 100644
--- a/toolkit/source/controls/eventcontainer.cxx
+++ b/toolkit/source/controls/eventcontainer.cxx
@@ -46,33 +46,33 @@ Type ScriptEventContainer::getElementType()
sal_Bool ScriptEventContainer::hasElements()
{
- return !mHashMap.empty();
+ bool bRet = (mnElementCount > 0);
+ return bRet;
}
// Methods XNameAccess
Any ScriptEventContainer::getByName( const OUString& aName )
{
- auto aIt = mHashMap.find( aName );
+ NameContainerNameMap::iterator aIt = mHashMap.find( aName );
if( aIt == mHashMap.end() )
{
throw NoSuchElementException();
}
- return aIt->second;
+ sal_Int32 iHashResult = (*aIt).second;
+ Any aRetAny = mValues[ iHashResult ];
+ return aRetAny;
}
Sequence< OUString > ScriptEventContainer::getElementNames()
{
- Sequence<OUString> aRet(mHashMap.size());
- int i = 0;
- for (auto const & pair : mHashMap)
- aRet[i++] = pair.first;
- return aRet;
+ return mNames;
}
sal_Bool ScriptEventContainer::hasByName( const OUString& aName )
{
- auto aIt = mHashMap.find( aName );
- return aIt != mHashMap.end();
+ NameContainerNameMap::iterator aIt = mHashMap.find( aName );
+ bool bRet = ( aIt != mHashMap.end() );
+ return bRet;
}
@@ -83,13 +83,14 @@ void ScriptEventContainer::replaceByName( const OUString& aName, const Any& aEle
if( mType != aAnyType )
throw IllegalArgumentException();
- auto aIt = mHashMap.find( aName );
+ NameContainerNameMap::iterator aIt = mHashMap.find( aName );
if( aIt == mHashMap.end() )
{
throw NoSuchElementException();
}
- Any aOldElement = aIt->second;
- aIt->second = aElement;
+ sal_Int32 iHashResult = (*aIt).second;
+ Any aOldElement = mValues[ iHashResult ];
+ mValues[ iHashResult ] = aElement;
// Fire event
ContainerEvent aEvent;
@@ -108,13 +109,18 @@ void ScriptEventContainer::insertByName( const OUString& aName, const Any& aElem
if( mType != aAnyType )
throw IllegalArgumentException();
- auto aIt = mHashMap.find( aName );
+ NameContainerNameMap::iterator aIt = mHashMap.find( aName );
if( aIt != mHashMap.end() )
{
throw ElementExistException();
}
- mHashMap[ aName ] = aElement;
+ sal_Int32 nCount = mNames.getLength();
+ mNames.realloc( nCount + 1 );
+ mValues.resize( nCount + 1 );
+ mNames.getArray()[ nCount ] = aName;
+ mValues[ nCount ] = aElement;
+ mHashMap[ aName ] = nCount;
// Fire event
ContainerEvent aEvent;
@@ -126,20 +132,33 @@ void ScriptEventContainer::insertByName( const OUString& aName, const Any& aElem
void ScriptEventContainer::removeByName( const OUString& Name )
{
- auto aIt = mHashMap.find( Name );
+ NameContainerNameMap::iterator aIt = mHashMap.find( Name );
if( aIt == mHashMap.end() )
{
throw NoSuchElementException();
}
+ sal_Int32 iHashResult = (*aIt).second;
+ Any aOldElement = mValues[ iHashResult ];
+
// Fire event
ContainerEvent aEvent;
aEvent.Source = *this;
- aEvent.Element = aIt->second;
+ aEvent.Element = aOldElement;
aEvent.Accessor <<= Name;
maContainerListeners.elementRemoved( aEvent );
mHashMap.erase( aIt );
+ sal_Int32 iLast = mNames.getLength() - 1;
+ if( iLast != iHashResult )
+ {
+ OUString* pNames = mNames.getArray();
+ pNames[ iHashResult ] = pNames[ iLast ];
+ mValues[ iHashResult ] = mValues[ iLast ];
+ mHashMap[ pNames[ iHashResult ] ] = iHashResult;
+ }
+ mNames.realloc( iLast );
+ mValues.resize( iLast );
}
// Methods XContainer
@@ -155,7 +174,8 @@ void ScriptEventContainer::removeContainerListener( const css::uno::Reference< c
ScriptEventContainer::ScriptEventContainer()
- : mType( cppu::UnoType<ScriptEventDescriptor>::get() ),
+ : mnElementCount( 0 ),
+ mType( cppu::UnoType<ScriptEventDescriptor>::get() ),
maContainerListeners( *this )
{
}
More information about the Libreoffice-commits
mailing list