cppu/source/typelib/typelib.cxx | 15 +- stoc/source/inspect/introspection.cxx | 172 +++++----------------------------- stoc/source/inspect/makefile.mk | 3 3 files changed, 37 insertions(+), 153 deletions(-)
New commits: commit 9d54084d61afc45beeff76e84277e3b814b32a73 Author: Stephan Bergmann <sberg...@redhat.com> Date: Mon Jan 2 18:00:40 2012 +0100 Replace dynamic array with std::vector. diff --git a/cppu/source/typelib/typelib.cxx b/cppu/source/typelib/typelib.cxx index c197f73..436781e 100644 --- a/cppu/source/typelib/typelib.cxx +++ b/cppu/source/typelib/typelib.cxx @@ -287,20 +287,21 @@ TypeDescriptor_Init_Impl::~TypeDescriptor_Init_Impl() SAL_THROW( () ) if( pWeakMap ) { - sal_Int32 nSize = pWeakMap->size(); - typelib_TypeDescriptionReference ** ppTDR = new typelib_TypeDescriptionReference *[ nSize ]; + std::vector< typelib_TypeDescriptionReference * > ppTDR; // save al weak references WeakMap_Impl::const_iterator aIt = pWeakMap->begin(); - sal_Int32 i = 0; while( aIt != pWeakMap->end() ) { - typelib_typedescriptionreference_acquire( ppTDR[i++] = (*aIt).second ); + ppTDR.push_back( (*aIt).second ); + typelib_typedescriptionreference_acquire( ppTDR.back() ); ++aIt; } - for( i = 0; i < nSize; i++ ) + for( std::vector< typelib_TypeDescriptionReference * >::iterator i( + ppTDR.begin() ); + i != ppTDR.end(); ++i ) { - typelib_TypeDescriptionReference * pTDR = ppTDR[i]; + typelib_TypeDescriptionReference * pTDR = *i; OSL_ASSERT( pTDR->nRefCount > pTDR->nStaticRefCount ); pTDR->nRefCount -= pTDR->nStaticRefCount; @@ -312,8 +313,6 @@ TypeDescriptor_Init_Impl::~TypeDescriptor_Init_Impl() SAL_THROW( () ) typelib_typedescriptionreference_release( pTDR ); } - delete [] ppTDR; - #if OSL_DEBUG_LEVEL > 1 aIt = pWeakMap->begin(); while( aIt != pWeakMap->end() ) commit 13a40f304112a6c9ad232ea1de547e019b045e61 Author: Stephan Bergmann <sberg...@redhat.com> Date: Mon Jan 2 18:00:01 2012 +0100 Get rid of manual ref counting. diff --git a/stoc/source/inspect/introspection.cxx b/stoc/source/inspect/introspection.cxx index c2aeb49..1cb278d 100644 --- a/stoc/source/inspect/introspection.cxx +++ b/stoc/source/inspect/introspection.cxx @@ -40,6 +40,7 @@ #include <cppuhelper/factory.hxx> #include <cppuhelper/implbase3.hxx> #include <cppuhelper/typeprovider.hxx> +#include <salhelper/simplereferenceobject.hxx> #include <com/sun/star/uno/DeploymentException.hpp> #include <com/sun/star/lang/XSingleServiceFactory.hpp> @@ -64,6 +65,7 @@ #include <com/sun/star/container/XIndexContainer.hpp> #include <com/sun/star/container/XEnumerationAccess.hpp> +#include <rtl/ref.hxx> #include <rtl/ustrbuf.hxx> #include <rtl/strbuf.hxx> #include <boost/unordered_map.hpp> @@ -143,9 +145,6 @@ sal_Bool isDerivedFrom( Reference<XIdlClass> xToTestClass, Reference<XIdlClass> // Entspricht dem alten IntrospectionAccessImpl, bildet jetzt den statischen // Anteil des neuen Instanz-bezogenen ImplIntrospectionAccess -// ACHTUNG !!! Von Hand refcounten !!! - - // Hashtable fuer die Suche nach Namen struct hashName_Impl { @@ -186,7 +185,7 @@ LowerToExactNameMap; class ImplIntrospectionAccess; -class IntrospectionAccessStatic_Impl +class IntrospectionAccessStatic_Impl: public salhelper::SimpleReferenceObject { friend class ImplIntrospection; friend class ImplIntrospectionAccess; @@ -254,10 +253,6 @@ class IntrospectionAccessStatic_Impl void checkInterfaceArraySize( Sequence< Reference<XInterface> >& rSeq, Reference<XInterface>*& rpInterfaceArray, sal_Int32 iNextIndex ); - // RefCount - sal_Int32 nRefCount; - - public: IntrospectionAccessStatic_Impl( Reference< XIdlReflection > xCoreReflection_ ); ~IntrospectionAccessStatic_Impl() @@ -267,14 +262,6 @@ public: sal_Int32 getPropertyIndex( const OUString& aPropertyName ) const; sal_Int32 getMethodIndex( const OUString& aMethodName ) const; - void acquire() { nRefCount++; } - void release() - { - nRefCount--; - if( nRefCount <= 0 ) - delete this; - } - // Methoden von XIntrospectionAccess (ALT, jetzt nur Impl) void setPropertyValue(const Any& obj, const OUString& aPropertyName, const Any& aValue) const; // void setPropertyValue(Any& obj, const OUString& aPropertyName, const Any& aValue) const; @@ -314,14 +301,8 @@ IntrospectionAccessStatic_Impl::IntrospectionAccessStatic_Impl( Reference< XIdlR // Method-Daten mnMethCount = 0; - - // Eigenens RefCounting - nRefCount = 0; } -// Von Hand refcounten !!! - - sal_Int32 IntrospectionAccessStatic_Impl::getPropertyIndex( const OUString& aPropertyName ) const { sal_Int32 iHashResult = -1; @@ -738,7 +719,7 @@ class ImplIntrospectionAdapter : const Any& mrInspectedObject; // Statische Daten der Introspection - IntrospectionAccessStatic_Impl* mpStaticImpl; + rtl::Reference< IntrospectionAccessStatic_Impl > mpStaticImpl; // Objekt als Interface Reference<XInterface> mxIface; @@ -754,8 +735,8 @@ class ImplIntrospectionAdapter : public: ImplIntrospectionAdapter( ImplIntrospectionAccess* pAccess_, - const Any& obj, IntrospectionAccessStatic_Impl* pStaticImpl_ ); - ~ImplIntrospectionAdapter(); + const Any& obj, + rtl::Reference< IntrospectionAccessStatic_Impl > const & pStaticImpl_ ); // Methoden von XInterface virtual Any SAL_CALL queryInterface( const Type& rType ) throw( RuntimeException ); @@ -833,11 +814,10 @@ public: }; ImplIntrospectionAdapter::ImplIntrospectionAdapter( ImplIntrospectionAccess* pAccess_, - const Any& obj, IntrospectionAccessStatic_Impl* pStaticImpl_ ) + const Any& obj, + rtl::Reference< IntrospectionAccessStatic_Impl > const & pStaticImpl_ ) : mpAccess( pAccess_), mrInspectedObject( obj ), mpStaticImpl( pStaticImpl_ ) { - mpStaticImpl->acquire(); - // Objekt als Interfaceholen TypeClass eType = mrInspectedObject.getValueType().getTypeClass(); if( eType == TypeClass_INTERFACE ) @@ -854,11 +834,6 @@ ImplIntrospectionAdapter::ImplIntrospectionAdapter( ImplIntrospectionAccess* pAc } } -ImplIntrospectionAdapter::~ImplIntrospectionAdapter() -{ - mpStaticImpl->release(); -} - // Methoden von XInterface Any SAL_CALL ImplIntrospectionAdapter::queryInterface( const Type& rType ) throw( RuntimeException ) @@ -908,10 +883,10 @@ class ImplIntrospectionAccess : IntrospectionAccessHelper Reference<XInterface> mxIface; // Statische Daten der Introspection - IntrospectionAccessStatic_Impl* mpStaticImpl; + rtl::Reference< IntrospectionAccessStatic_Impl > mpStaticImpl; // Adapter-Implementation - ImplIntrospectionAdapter* mpAdapter; + rtl::Reference< ImplIntrospectionAdapter > mpAdapter; // Letzte Sequence, die bei getProperties geliefert wurde (Optimierung) Sequence<Property> maLastPropertySeq; @@ -922,8 +897,7 @@ class ImplIntrospectionAccess : IntrospectionAccessHelper sal_Int32 mnLastMethodConcept; public: - ImplIntrospectionAccess( const Any& obj, IntrospectionAccessStatic_Impl* pStaticImpl_ ); - ~ImplIntrospectionAccess(); + ImplIntrospectionAccess( const Any& obj, rtl::Reference< IntrospectionAccessStatic_Impl > const & pStaticImpl_ ); // Methoden von XIntrospectionAccess virtual sal_Int32 SAL_CALL getSuppliedMethodConcepts(void) @@ -956,11 +930,9 @@ public: }; ImplIntrospectionAccess::ImplIntrospectionAccess - ( const Any& obj, IntrospectionAccessStatic_Impl* pStaticImpl_ ) - : maInspectedObject( obj ), mpStaticImpl( pStaticImpl_ ), mpAdapter( NULL ) + ( const Any& obj, rtl::Reference< IntrospectionAccessStatic_Impl > const & pStaticImpl_ ) + : maInspectedObject( obj ), mpStaticImpl( pStaticImpl_ ) { - mpStaticImpl->acquire(); - // Objekt als Interface merken, wenn moeglich TypeClass eType = maInspectedObject.getValueType().getTypeClass(); if( eType == TypeClass_INTERFACE ) @@ -970,16 +942,6 @@ ImplIntrospectionAccess::ImplIntrospectionAccess mnLastMethodConcept = -1; } -ImplIntrospectionAccess::~ImplIntrospectionAccess() -{ - mpStaticImpl->release(); - - // Eigene Referenz loslassen - if (mpAdapter) - mpAdapter->release(); -} - - //*************************************************** //*** Implementation von ImplIntrospectionAdapter *** //*************************************************** @@ -1440,13 +1402,10 @@ Reference<XInterface> SAL_CALL ImplIntrospectionAccess::queryAdapter( const Type throw( IllegalTypeException, RuntimeException ) { // Gibt es schon einen Adapter? - if( !mpAdapter ) + if( !mpAdapter.is() ) { ((ImplIntrospectionAccess*)this)->mpAdapter = new ImplIntrospectionAdapter( this, maInspectedObject, mpStaticImpl ); - - // Selbst eine Referenz halten - mpAdapter->acquire(); } Reference<XInterface> xRet; @@ -1543,29 +1502,11 @@ struct hashIntrospectionAccessCache_Impl typedef boost::unordered_map < hashIntrospectionKey_Impl, - IntrospectionAccessStatic_Impl*, + rtl::Reference< IntrospectionAccessStatic_Impl >, hashIntrospectionAccessCache_Impl, hashIntrospectionAccessCache_Impl > -IntrospectionAccessCacheMap_Impl; - -class IntrospectionAccessCacheMap : public IntrospectionAccessCacheMap_Impl -{ -public: - ~IntrospectionAccessCacheMap() - { - IntrospectionAccessCacheMap::iterator iter = begin(); - IntrospectionAccessCacheMap::iterator stop = this->end(); - while( iter != stop ) - { - - (*iter).second->release(); - (*iter).second = NULL; - ++iter; - } - } -}; - +IntrospectionAccessCacheMap; // For XTypeProvider struct hashTypeProviderKey_Impl @@ -1642,27 +1583,11 @@ size_t TypeProviderAccessCache_Impl::operator()(const hashTypeProviderKey_Impl & typedef boost::unordered_map < hashTypeProviderKey_Impl, - IntrospectionAccessStatic_Impl*, + rtl::Reference< IntrospectionAccessStatic_Impl >, TypeProviderAccessCache_Impl, TypeProviderAccessCache_Impl > -TypeProviderAccessCacheMap_Impl; - -class TypeProviderAccessCacheMap : public TypeProviderAccessCacheMap_Impl -{ -public: - ~TypeProviderAccessCacheMap() - { - TypeProviderAccessCacheMap::iterator iter = begin(); - TypeProviderAccessCacheMap::iterator stop = this->end(); - while( iter != stop ) - { - (*iter).second->release(); - (*iter).second = NULL; - ++iter; - } - } -}; +TypeProviderAccessCacheMap; //************************* //*** ImplIntrospection *** @@ -1682,8 +1607,7 @@ class ImplIntrospection : public XIntrospection friend class ImplMVCIntrospection; // Implementation der Introspection. - // ACHTUNG: RefCounting von Hand !!! - IntrospectionAccessStatic_Impl* implInspect(const Any& aToInspectObj); + rtl::Reference< IntrospectionAccessStatic_Impl > implInspect(const Any& aToInspectObj); // Save XMultiServiceFactory from createComponent Reference<XMultiServiceFactory> m_xSMgr; @@ -1923,15 +1847,15 @@ Reference<XIntrospectionAccess> ImplIntrospection::inspect(const Any& aToInspect Any aRealInspectObj; aRealInspectObj <<= xIdlClass; - IntrospectionAccessStatic_Impl* pStaticImpl = implInspect( aRealInspectObj ); - if( pStaticImpl ) + rtl::Reference< IntrospectionAccessStatic_Impl > pStaticImpl( implInspect( aRealInspectObj ) ); + if( pStaticImpl.is() ) xAccess = new ImplIntrospectionAccess( aRealInspectObj, pStaticImpl ); } } else { - IntrospectionAccessStatic_Impl* pStaticImpl = implInspect( aToInspectObj ); - if( pStaticImpl ) + rtl::Reference< IntrospectionAccessStatic_Impl > pStaticImpl( implInspect( aToInspectObj ) ); + if( pStaticImpl.is() ) xAccess = new ImplIntrospectionAccess( aToInspectObj, pStaticImpl ); } @@ -1991,7 +1915,7 @@ Reference<XIdlClass> TypeToIdlClass( const Type& rType, const Reference< XMultiS } // Implementation der Introspection. -IntrospectionAccessStatic_Impl* ImplIntrospection::implInspect(const Any& aToInspectObj) +rtl::Reference< IntrospectionAccessStatic_Impl > ImplIntrospection::implInspect(const Any& aToInspectObj) { MutexGuard aGuard( m_mutex ); @@ -2022,7 +1946,7 @@ IntrospectionAccessStatic_Impl* ImplIntrospection::implInspect(const Any& aToIns TypeProviderAccessCacheMap& aTPCache = *mpTypeProviderCache; // Pointer auf ggf. noetige neue IntrospectionAccess-Instanz - IntrospectionAccessStatic_Impl* pAccess = NULL; + rtl::Reference< IntrospectionAccessStatic_Impl > pAccess; // Pruefen: Ist schon ein passendes Access-Objekt gecached? Sequence< Reference<XIdlClass> > SupportedClassSeq; @@ -2087,10 +2011,6 @@ IntrospectionAccessStatic_Impl* ImplIntrospection::implInspect(const Any& aToIns // Neue Instanz anlegen und unter dem gegebenen Key einfuegen pAccess = new IntrospectionAccessStatic_Impl( mxCoreReflection ); - // RefCount von Hand erhoehen, muss beim Entfernen - // aus der Hashtable wieder released werden - pAccess->acquire(); - // Groesse begrenzen, alten Eintrag wieder rausschmeissen if( mnTPCacheEntryCount > INTROSPECTION_CACHE_MAX_SIZE ) { @@ -2104,11 +2024,6 @@ IntrospectionAccessStatic_Impl* ImplIntrospection::implInspect(const Any& aToIns toDelete = iter; ++iter; } - - // Gefundenen Eintrag entfernen - if( (*toDelete).second ) - (*toDelete).second->release(); - (*toDelete).second = NULL; aTPCache.erase( toDelete ); } else @@ -2139,10 +2054,6 @@ IntrospectionAccessStatic_Impl* ImplIntrospection::implInspect(const Any& aToIns // Neue Instanz anlegen und unter dem gegebenen Key einfuegen pAccess = new IntrospectionAccessStatic_Impl( mxCoreReflection ); - // RefCount von Hand erhoehen, muss beim Entfernen - // aus der Hashtable wieder released werden - pAccess->acquire(); - // Groesse begrenzen, alten Eintrag wieder rausschmeissen if( mnCacheEntryCount > INTROSPECTION_CACHE_MAX_SIZE ) { @@ -2156,11 +2067,6 @@ IntrospectionAccessStatic_Impl* ImplIntrospection::implInspect(const Any& aToIns toDelete = iter; ++iter; } - - // Gefundenen Eintrag entfernen - if( (*toDelete).second ) - (*toDelete).second->release(); - (*toDelete).second = NULL; aCache.erase( toDelete ); } else @@ -2187,7 +2093,7 @@ IntrospectionAccessStatic_Impl* ImplIntrospection::implInspect(const Any& aToIns sal_Int32* pPropertyConceptArray; sal_Int32 i; - if( !pAccess ) + if( !pAccess.is() ) pAccess = new IntrospectionAccessStatic_Impl( mxCoreReflection ); // Referenzen auf wichtige Daten von pAccess @@ -2427,7 +2333,7 @@ IntrospectionAccessStatic_Impl* ImplIntrospection::implInspect(const Any& aToIns // Methoden katalogisieren // Alle (?) Methoden von XInterface filtern, damit z.B. nicht - // vom Scripting aus aquire oder release gerufen werden kann + // vom Scripting aus acquire oder release gerufen werden kann if( rxMethod_i->getDeclaringClass()->equals( mxInterfaceClass ) ) { // XInterface-Methoden sind hiermit einmal beruecksichtigt diff --git a/stoc/source/inspect/makefile.mk b/stoc/source/inspect/makefile.mk index 62bf365..37b8ec6 100644 --- a/stoc/source/inspect/makefile.mk +++ b/stoc/source/inspect/makefile.mk @@ -48,7 +48,8 @@ SHL1TARGET= $(TARGET) SHL1STDLIBS= \ $(CPPULIB) \ $(CPPUHELPERLIB) \ - $(SALLIB) + $(SALLIB) \ + $(SALHELPERLIB) SHL1VERSIONMAP = $(SOLARENV)/src/component.map SHL1RPATH=URELIB commit c28c09a8b24cd5927b2bec94208fe239f037a68c Author: Stephan Bergmann <sberg...@redhat.com> Date: Mon Jan 2 15:45:18 2012 +0100 USE_INTROSPECTION_CACHE is always defined. diff --git a/stoc/source/inspect/introspection.cxx b/stoc/source/inspect/introspection.cxx index 3b0ecf6..c2aeb49 100644 --- a/stoc/source/inspect/introspection.cxx +++ b/stoc/source/inspect/introspection.cxx @@ -29,12 +29,8 @@ #include <string.h> -// Schalter fuer Introspection-Caching -#define USE_INTROSPECTION_CACHE - -#ifdef USE_INTROSPECTION_CACHE #define INTROSPECTION_CACHE_MAX_SIZE 100 -#endif + #include <osl/diagnose.h> #include <osl/mutex.hxx> #include <osl/thread.h> @@ -1491,8 +1487,6 @@ OUString ImplIntrospectionAccess::getExactName( const OUString& rApproximateName //----------------------------------------------------------------------------- -#ifdef USE_INTROSPECTION_CACHE - struct hashIntrospectionKey_Impl { Sequence< Reference<XIdlClass> > aIdlClasses; @@ -1670,9 +1664,6 @@ public: } }; -#endif - - //************************* //*** ImplIntrospection *** //************************* @@ -1711,12 +1702,10 @@ class ImplIntrospection : public XIntrospection Reference<XIdlClass> mxAggregationClass; sal_Bool mbDisposed; -#ifdef USE_INTROSPECTION_CACHE sal_uInt16 mnCacheEntryCount; sal_uInt16 mnTPCacheEntryCount; IntrospectionAccessCacheMap* mpCache; TypeProviderAccessCacheMap* mpTypeProviderCache; -#endif public: ImplIntrospection( const Reference<XMultiServiceFactory> & rXSMgr ); @@ -1760,12 +1749,10 @@ ImplIntrospection::ImplIntrospection( const Reference<XMultiServiceFactory> & rX : OComponentHelper( m_mutex ) , m_xSMgr( rXSMgr ) { -#ifdef USE_INTROSPECTION_CACHE mnCacheEntryCount = 0; mnTPCacheEntryCount = 0; mpCache = NULL; mpTypeProviderCache = NULL; -#endif // Spezielle Klassen holen // Reference< XInterface > xServiceIface = m_xSMgr->createInstance( OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.reflection.CoreReflection")) ); @@ -1809,13 +1796,11 @@ void ImplIntrospection::dispose() throw(::com::sun::star::uno::RuntimeException) { OComponentHelper::dispose(); -#ifdef USE_INTROSPECTION_CACHE // Cache loeschen delete mpCache; mpCache = NULL; delete mpTypeProviderCache; mpTypeProviderCache = NULL; -#endif mxElementAccessClass = NULL; mxNameContainerClass = NULL; @@ -2028,7 +2013,6 @@ IntrospectionAccessStatic_Impl* ImplIntrospection::implInspect(const Any& aToIns return NULL; } -#ifdef USE_INTROSPECTION_CACHE // Haben wir schon eine Cache-Instanz if( !mpCache ) mpCache = new IntrospectionAccessCacheMap; @@ -2039,10 +2023,6 @@ IntrospectionAccessStatic_Impl* ImplIntrospection::implInspect(const Any& aToIns // Pointer auf ggf. noetige neue IntrospectionAccess-Instanz IntrospectionAccessStatic_Impl* pAccess = NULL; -#else - // Pointer auf ggf. noetige neue IntrospectionAccess-Instanz - IntrospectionAccessStatic_Impl* pAccess = new IntrospectionAccessStatic_Impl( mxCoreReflection ); -#endif // Pruefen: Ist schon ein passendes Access-Objekt gecached? Sequence< Reference<XIdlClass> > SupportedClassSeq; @@ -2090,7 +2070,6 @@ IntrospectionAccessStatic_Impl* ImplIntrospection::implInspect(const Any& aToIns xImplClass = TypeToIdlClass( aToInspectObj.getValueType(), m_xSMgr ); } -#ifdef USE_INTROSPECTION_CACHE if( xTypeProvider.is() ) { Sequence< sal_Int8 > aImpIdSeq = xTypeProvider->getImplementationId(); @@ -2199,7 +2178,6 @@ IntrospectionAccessStatic_Impl* ImplIntrospection::implInspect(const Any& aToIns return (*aIt).second; } } -#endif // Kein Access gecached -> neu anlegen Property* pAllPropArray; _______________________________________________ Libreoffice-commits mailing list Libreoffice-commits@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits