diff options
author | Kohei Yoshida <kohei.yoshida@suse.com> | 2011-08-11 00:46:42 -0400 |
---|---|---|
committer | Kohei Yoshida <kohei.yoshida@suse.com> | 2011-08-16 21:22:40 -0400 |
commit | 85696df0b13e18f3782d196f50baa06bf099e0ef (patch) | |
tree | 4c569da9a905ee92beca6a8c5f21f757a8f9f04d | |
parent | 98dc4bb8a1d029ba8b01504b74ed5397e1e7164b (diff) |
Fixed a crash due to invalid index for Sequence.
With this, 3.81 sec -> 1.2 sec.
-rw-r--r-- | comphelper/source/eventattachermgr/eventattachermgr.cxx | 43 | ||||
-rw-r--r-- | eventattacher/source/eventattacher.cxx | 3 |
2 files changed, 26 insertions, 20 deletions
diff --git a/comphelper/source/eventattachermgr/eventattachermgr.cxx b/comphelper/source/eventattachermgr/eventattachermgr.cxx index f7a7d76c635f..e9d52290d460 100644 --- a/comphelper/source/eventattachermgr/eventattachermgr.cxx +++ b/comphelper/source/eventattachermgr/eventattachermgr.cxx @@ -47,7 +47,7 @@ #include <com/sun/star/reflection/XIdlMethod.hpp> #include <com/sun/star/script/XTypeConverter.hpp> #include <com/sun/star/script/XEngineListener.hpp> -#include <com/sun/star/script/XEventAttacher.hpp> +#include <com/sun/star/script/XEventAttacher2.hpp> #include <com/sun/star/script/XEventAttacherManager.hpp> #include <com/sun/star/script/XScriptListener.hpp> #include <cppuhelper/weak.hxx> @@ -103,7 +103,7 @@ class ImplEventAttacherManager // Container fuer die ScriptListener OInterfaceContainerHelper aScriptListeners; // EventAttacher-Instanz - Reference< XEventAttacher > xAttacher; + Reference< XEventAttacher2 > xAttacher; Reference< XMultiServiceFactory > mxSMgr; Reference< XIdlReflection > mxCoreReflection; Reference< XIntrospection > mxIntrospection; @@ -403,7 +403,7 @@ ImplEventAttacherManager::ImplEventAttacherManager( const Reference< XIntrospect Reference< XInterface > xIFace( rSMgr->createInstance( OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.script.EventAttacher" )) ) ); if ( xIFace.is() ) { - xAttacher = Reference< XEventAttacher >::query( xIFace ); + xAttacher = Reference< XEventAttacher2 >::query( xIFace ); } xIFace = rSMgr->createInstance( OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.script.Converter" )) ); if ( xIFace.is() ) @@ -692,28 +692,33 @@ void SAL_CALL ImplEventAttacherManager::attach(sal_Int32 nIndex, const Reference //::std::deque< AttachedObject_Impl >::iterator aObjIt = (*aIt).aObjList.back(); AttachedObject_Impl & rCurObj = aCurrentPosition->aObjList.back(); rCurObj.aAttachedListenerSeq = Sequence< Reference< XEventListener > >( aCurrentPosition->aEventList.size() ); - Reference< XEventListener > * pArray = rCurObj.aAttachedListenerSeq.getArray(); - ::std::deque< ScriptEventDescriptor >::iterator aEvtIt = aCurrentPosition->aEventList.begin(); - ::std::deque< ScriptEventDescriptor >::iterator aEvtEnd = aCurrentPosition->aEventList.end(); - sal_Int32 i = 0; - while( aEvtIt != aEvtEnd ) + if (!aCurrentPosition->aEventList.empty()) { - Reference< XAllListener > xAll = - new AttacherAllListener_Impl( this, (*aEvtIt).ScriptType, (*aEvtIt).ScriptCode ); - Reference< XEventListener > xAdapter; - try + Sequence<com::sun::star::script::EventListener> aEvents(aCurrentPosition->aEventList.size()); + std::deque<ScriptEventDescriptor>::iterator itr = aCurrentPosition->aEventList.begin(); + std::deque<ScriptEventDescriptor>::iterator itrEnd = aCurrentPosition->aEventList.end(); + ::com::sun::star::script::EventListener* p = aEvents.getArray(); + size_t i = 0; + for (; itr != itrEnd; ++itr) { - xAdapter = xAttacher->attachSingleEventListener( rCurObj.xTarget, xAll, - rCurObj.aHelper, (*aEvtIt).ListenerType, - (*aEvtIt).AddListenerParam, (*aEvtIt).EventMethod ); + com::sun::star::script::EventListener aListener; + aListener.AllListener = + new AttacherAllListener_Impl(this, itr->ScriptType, itr->ScriptCode); + aListener.Helper = rCurObj.aHelper; + aListener.ListenerType = itr->ListenerType; + aListener.EventMethod = itr->EventMethod; + aListener.AddListenerParam = itr->AddListenerParam; + p[i++] = aListener; } - catch( Exception& ) + + try + { + rCurObj.aAttachedListenerSeq = xAttacher->attachMultipleEventListeners(rCurObj.xTarget, aEvents); + } + catch (const Exception&) { } - - pArray[i++] = xAdapter; - ++aEvtIt; } } diff --git a/eventattacher/source/eventattacher.cxx b/eventattacher/source/eventattacher.cxx index 7deb8113224c..79879684fc56 100644 --- a/eventattacher/source/eventattacher.cxx +++ b/eventattacher/source/eventattacher.cxx @@ -743,6 +743,7 @@ Sequence< Reference<XEventListener> > EventAttacherImpl::attachListeners( return Sequence< Reference<XEventListener> >(); Sequence< Reference<XEventListener> > aRet(nCount); + Reference<XEventListener>* pArray = aRet.getArray(); for (sal_Int32 i = 0; i < nCount; ++i) { @@ -846,7 +847,7 @@ Sequence< Reference<XEventListener> > EventAttacherImpl::attachListeners( // Anything else is not supported } } - aRet[nCount] = xRet; + pArray[i] = xRet; } return aRet; |