summaryrefslogtreecommitdiff
path: root/toolkit
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2017-07-20 12:41:28 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2017-07-20 15:09:20 +0200
commit85f08e3e34bea01456eaf8989ac4f77d3900d5c5 (patch)
treeed03d7dcb54d1c691aec047710c5e52218aeb23d /toolkit
parentb1601f7333181a04583612ac3b73e68bd7842c88 (diff)
remove some "optimisation" insanity in ScriptEventContainer
I can only imagine the weird bugs that must have periodically resulted when we had a hash value collision. In the process, fix hasElements() to return a useful value Change-Id: I1d9a052e73332b4b2bbc9c1fd8142c13eb22f1be Reviewed-on: https://gerrit.libreoffice.org/40226 Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk> Tested-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'toolkit')
-rw-r--r--toolkit/source/controls/eventcontainer.cxx56
1 files changed, 18 insertions, 38 deletions
diff --git a/toolkit/source/controls/eventcontainer.cxx b/toolkit/source/controls/eventcontainer.cxx
index 3cc2aa802773..f4df038c405a 100644
--- a/toolkit/source/controls/eventcontainer.cxx
+++ b/toolkit/source/controls/eventcontainer.cxx
@@ -46,33 +46,33 @@ Type ScriptEventContainer::getElementType()
sal_Bool ScriptEventContainer::hasElements()
{
- bool bRet = (mnElementCount > 0);
- return bRet;
+ return !mHashMap.empty();
}
// Methods XNameAccess
Any ScriptEventContainer::getByName( const OUString& aName )
{
- NameContainerNameMap::iterator aIt = mHashMap.find( aName );
+ auto aIt = mHashMap.find( aName );
if( aIt == mHashMap.end() )
{
throw NoSuchElementException();
}
- sal_Int32 iHashResult = (*aIt).second;
- Any aRetAny = mValues[ iHashResult ];
- return aRetAny;
+ return aIt->second;
}
Sequence< OUString > ScriptEventContainer::getElementNames()
{
- return mNames;
+ Sequence<OUString> aRet(mHashMap.size());
+ int i = 0;
+ for (auto const & pair : mHashMap)
+ aRet[i++] = pair.first;
+ return aRet;
}
sal_Bool ScriptEventContainer::hasByName( const OUString& aName )
{
- NameContainerNameMap::iterator aIt = mHashMap.find( aName );
- bool bRet = ( aIt != mHashMap.end() );
- return bRet;
+ auto aIt = mHashMap.find( aName );
+ return aIt != mHashMap.end();
}
@@ -83,14 +83,13 @@ void ScriptEventContainer::replaceByName( const OUString& aName, const Any& aEle
if( mType != aAnyType )
throw IllegalArgumentException();
- NameContainerNameMap::iterator aIt = mHashMap.find( aName );
+ auto aIt = mHashMap.find( aName );
if( aIt == mHashMap.end() )
{
throw NoSuchElementException();
}
- sal_Int32 iHashResult = (*aIt).second;
- Any aOldElement = mValues[ iHashResult ];
- mValues[ iHashResult ] = aElement;
+ Any aOldElement = aIt->second;
+ aIt->second = aElement;
// Fire event
ContainerEvent aEvent;
@@ -109,18 +108,13 @@ void ScriptEventContainer::insertByName( const OUString& aName, const Any& aElem
if( mType != aAnyType )
throw IllegalArgumentException();
- NameContainerNameMap::iterator aIt = mHashMap.find( aName );
+ auto aIt = mHashMap.find( aName );
if( aIt != mHashMap.end() )
{
throw ElementExistException();
}
- sal_Int32 nCount = mNames.getLength();
- mNames.realloc( nCount + 1 );
- mValues.resize( nCount + 1 );
- mNames.getArray()[ nCount ] = aName;
- mValues[ nCount ] = aElement;
- mHashMap[ aName ] = nCount;
+ mHashMap[ aName ] = aElement;
// Fire event
ContainerEvent aEvent;
@@ -132,33 +126,20 @@ void ScriptEventContainer::insertByName( const OUString& aName, const Any& aElem
void ScriptEventContainer::removeByName( const OUString& Name )
{
- NameContainerNameMap::iterator aIt = mHashMap.find( Name );
+ auto 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 = aOldElement;
+ aEvent.Element = aIt->second;
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
@@ -174,8 +155,7 @@ void ScriptEventContainer::removeContainerListener( const css::uno::Reference< c
ScriptEventContainer::ScriptEventContainer()
- : mnElementCount( 0 ),
- mType( cppu::UnoType<ScriptEventDescriptor>::get() ),
+ : mType( cppu::UnoType<ScriptEventDescriptor>::get() ),
maContainerListeners( *this )
{
}