From 1ad713ebac228b34b3bb5fd59f7bc7f49ddf9628 Mon Sep 17 00:00:00 2001 From: Martin Gallwey Date: Fri, 14 Sep 2001 14:10:38 +0000 Subject: #89303# optimisations --- package/source/zippackage/ZipPackageEntry.cxx | 120 +++++++++++++------------- package/source/zippackage/ZipPackageEntry.hxx | 35 +++++--- 2 files changed, 84 insertions(+), 71 deletions(-) diff --git a/package/source/zippackage/ZipPackageEntry.cxx b/package/source/zippackage/ZipPackageEntry.cxx index 964f51008131..a493a14bea12 100644 --- a/package/source/zippackage/ZipPackageEntry.cxx +++ b/package/source/zippackage/ZipPackageEntry.cxx @@ -2,9 +2,9 @@ * * $RCSfile: ZipPackageEntry.cxx,v $ * - * $Revision: 1.19 $ + * $Revision: 1.20 $ * - * last change: $Author: mtg $ $Date: 2001-07-04 14:56:37 $ + * last change: $Author: mtg $ $Date: 2001-09-14 15:10:38 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -64,15 +64,24 @@ #ifndef _COM_SUN_STAR_PACKAGE_ZIP_ZIPCONSTANTS_HPP_ #include #endif -#ifndef _COM_SUN_STAR_CONTAINER_XNAMECONTAINER_HPP_ -#include -#endif #ifndef _VOS_DIAGNOSE_H_ #include #endif #ifndef _IMPL_VALID_CHARACTERS_HXX_ #include #endif +#ifndef _ZIP_PACKAGE_FOLDER_HXX +#include +#endif +#ifndef _ZIP_PACKAGE_STREAM_HXX +#include +#endif +#ifndef _CONTENT_INFO_HXX_ +#include +#endif +#ifndef _CPPUHELPER_TYPEPROVIDER_HXX_ +#include +#endif using namespace rtl; using namespace com::sun::star; @@ -82,40 +91,16 @@ using namespace com::sun::star::container; using namespace com::sun::star::packages::zip; using namespace com::sun::star::packages::zip::ZipConstants; -ZipPackageEntry::ZipPackageEntry (void) +ZipPackageEntry::ZipPackageEntry ( bool bNewFolder ) +: pParent ( NULL ) +, mbIsFolder ( bNewFolder ) { } -ZipPackageEntry::~ZipPackageEntry( void ) +ZipPackageEntry::~ZipPackageEntry() { } -/* I made these pure virtual to bypass a couple of virtual calls... - * acquire/release/queryInterface are called several thousand times in a single - * ZipPackage instance -Any SAL_CALL ZipPackageEntry::queryInterface( const Type& rType ) - throw(RuntimeException) -{ - return ( ::cppu::queryInterface ( rType , - // OWeakObject interfaces - static_cast< XWeak* > ( this ) , - static_cast< XInterface* > ( this ) , - // my own interfaces - static_cast< XNamed* > ( this ) , - static_cast< XUnoTunnel* > ( this ) , - static_cast< XChild* > ( this ) ) ); -} -void SAL_CALL ZipPackageEntry::acquire( ) - throw() -{ - OWeakObject::acquire(); -} -void SAL_CALL ZipPackageEntry::release( ) - throw() -{ - OWeakObject::release(); -} -*/ - // XChild +// XChild OUString SAL_CALL ZipPackageEntry::getName( ) throw(RuntimeException) { @@ -124,53 +109,52 @@ OUString SAL_CALL ZipPackageEntry::getName( ) void SAL_CALL ZipPackageEntry::setName( const OUString& aName ) throw(RuntimeException) { - Reference < XNameContainer > xCont (xParent, UNO_QUERY); - if (xCont.is() && xCont->hasByName ( aEntry.sName ) ) - xCont->removeByName ( aEntry.sName ); + if ( pParent && pParent->hasByName ( aEntry.sName ) ) + pParent->removeByName ( aEntry.sName ); const sal_Unicode *pChar = aName.getStr(); - for ( sal_Int32 i = 0, nEnd = aName.getLength(); i < nEnd; i++) - VOS_ENSURE ( Impl_IsValidChar (pChar[i], sal_False), "Invalid character in new zip package entry name!"); + VOS_ENSURE ( Impl_IsValidChar (pChar, static_cast < sal_Int16 > ( aName.getLength() ), sal_False), "Invalid character in new zip package entry name!"); aEntry.sName = aName; - if (xCont.is()) - { - Any aAny; - Reference < XUnoTunnel > xTunnel = this; - aAny <<= xTunnel; - xCont->insertByName ( aEntry.sName, aAny ); - } + if ( pParent ) + pParent->doInsertByName ( this, sal_False ); } Reference< XInterface > SAL_CALL ZipPackageEntry::getParent( ) throw(RuntimeException) { return xParent; } -void SAL_CALL ZipPackageEntry::setParent( const Reference< XInterface >& Parent ) - throw(NoSupportException, RuntimeException) + +void ZipPackageEntry::doSetParent ( ZipPackageFolder * pNewParent, sal_Bool bInsert ) { - Reference < XNameContainer > xOldParent (xParent, UNO_QUERY), xNewParent (Parent, UNO_QUERY); + xParent = pParent = pNewParent; + if ( bInsert && !pNewParent->hasByName ( aEntry.sName ) ) + pNewParent->doInsertByName ( this, sal_False ); +} - if ( !xNewParent.is()) +void SAL_CALL ZipPackageEntry::setParent( const Reference< XInterface >& xNewParent ) + throw(NoSupportException, RuntimeException) +{ + sal_Int64 nTest; + Reference < XUnoTunnel > xTunnel ( xNewParent, UNO_QUERY ); + if ( !xNewParent.is() || ( nTest = xTunnel->getSomething ( ZipPackageFolder::getUnoTunnelImplementationId () ) ) == 0 ) throw NoSupportException(); - if ( xOldParent != xNewParent ) + + ZipPackageFolder *pNewParent = reinterpret_cast < ZipPackageFolder * > ( nTest ); + + if ( pNewParent != pParent ) { - if ( xOldParent.is() && xOldParent->hasByName(getName())) - xOldParent->removeByName(getName()); - Any aAny; - Reference < XUnoTunnel > xTunnel = this; - aAny <<= xTunnel; - if (!xNewParent->hasByName(getName())) - xNewParent->insertByName(getName(), aAny); - xParent = Parent; + if ( pParent && pParent->hasByName ( aEntry.sName ) ) + pParent->removeByName( aEntry.sName ); + doSetParent ( pNewParent, sal_True ); } } //XPropertySet Reference< beans::XPropertySetInfo > SAL_CALL ZipPackageEntry::getPropertySetInfo( ) throw(RuntimeException) { - return Reference < beans::XPropertySetInfo > (NULL); + return Reference < beans::XPropertySetInfo > (); } void SAL_CALL ZipPackageEntry::addPropertyChangeListener( const OUString& aPropertyName, const Reference< beans::XPropertyChangeListener >& xListener ) throw(beans::UnknownPropertyException, WrappedTargetException, RuntimeException) @@ -188,3 +172,19 @@ void SAL_CALL ZipPackageEntry::removeVetoableChangeListener( const OUString& Pro throw(beans::UnknownPropertyException, WrappedTargetException, RuntimeException) { } +Sequence< sal_Int8 > ZipPackageEntry::getUnoTunnelImplementationId( void ) + throw (RuntimeException) +{ + static ::cppu::OImplementationId * pId = 0; + if (! pId) + { + ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ); + if (! pId) + { + static ::cppu::OImplementationId aId; + pId = &aId; + } + } + return pId->getImplementationId(); +} + diff --git a/package/source/zippackage/ZipPackageEntry.hxx b/package/source/zippackage/ZipPackageEntry.hxx index 929ce71c088a..c8541924dabe 100644 --- a/package/source/zippackage/ZipPackageEntry.hxx +++ b/package/source/zippackage/ZipPackageEntry.hxx @@ -2,9 +2,9 @@ * * $RCSfile: ZipPackageEntry.hxx,v $ * - * $Revision: 1.3 $ + * $Revision: 1.4 $ * - * last change: $Author: mtg $ $Date: 2001-07-04 14:56:37 $ + * last change: $Author: mtg $ $Date: 2001-09-14 15:08:31 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -67,9 +67,6 @@ #ifndef _COM_SUN_STAR_CONTAINER_XCHILD_HPP_ #include #endif -#ifndef _COM_SUN_STAR_PACKAGE_ZIP_ZIPENTRY_HPP_ -#include -#endif #ifndef _COM_SUN_STAR_CONTAINER_XNAMED_HPP_ #include #endif @@ -79,6 +76,14 @@ #ifndef _COM_SUN_STAR_LANG_XUNOTUNNEL_HPP_ #include #endif +#ifndef _COM_SUN_STAR_CONTAINER_XNAMECONTAINER_HPP_ +#include +#endif +#ifndef _ZIP_ENTRY_HXX_ +#include +#endif + +class ZipPackageFolder; class ZipPackageEntry : public com::sun::star::container::XNamed, public com::sun::star::container::XChild, @@ -86,19 +91,26 @@ class ZipPackageEntry : public com::sun::star::container::XNamed, public com::sun::star::beans::XPropertySet { protected: - com::sun::star::uno::Reference < com::sun::star::uno::XInterface > xParent; + bool mbIsFolder:1; + com::sun::star::uno::Reference < com::sun::star::container::XNameContainer > xParent; ::rtl::OUString sMediaType; + ZipPackageFolder * pParent; public: - com::sun::star::packages::zip::ZipEntry aEntry; + ZipEntry aEntry; + ZipPackageEntry ( bool bNewFolder ); + virtual ~ZipPackageEntry( void ); + + ::rtl::OUString & GetMediaType () { return sMediaType; } void SetMediaType ( ::rtl::OUString & sNewType) { sMediaType = sNewType; } - - ZipPackageEntry (void); - virtual ~ZipPackageEntry( void ); + void doSetParent ( ZipPackageFolder * pNewParent, sal_Bool bInsert ); + bool IsFolder ( ) { return mbIsFolder; } + ZipPackageFolder* GetParent ( ) { return pParent; } + void SetFolder ( bool bSetFolder ) { mbIsFolder = bSetFolder; } inline void clearParent ( void ) { - xParent = com::sun::star::uno::Reference < com::sun::star::uno::XInterface > (); + xParent = com::sun::star::uno::Reference < com::sun::star::container::XNameContainer > (); } // XInterface virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type& rType ) @@ -120,6 +132,7 @@ public: // XUnoTunnel virtual sal_Int64 SAL_CALL getSomething( const ::com::sun::star::uno::Sequence< sal_Int8 >& aIdentifier ) throw(::com::sun::star::uno::RuntimeException) = 0; + com::sun::star::uno::Sequence< sal_Int8 > getUnoTunnelImplementationId( void ); // XPropertySet virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo( ) throw(::com::sun::star::uno::RuntimeException); -- cgit v1.2.3