diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2014-03-07 23:39:25 +0100 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2014-03-10 08:59:23 +0100 |
commit | db5c67e1006664916b7b4c8881d21cf096333ee7 (patch) | |
tree | 02b11f8c940bbdd6071f2994ace7352255d500f2 | |
parent | f351fd1e8eb75a25e7844ac632e5837851b2aeed (diff) |
Keying on XTypeProvider::getImplementationId is unnecessary here
...given that cases where "every instance of getPropertySetInfo returns a new
object [...] must not be cached" anyway, so just key on the XPropertySetInfo
instances.
Change-Id: I11f0a1fe030226d1d26d6b6e6a2654f4511fdce8
-rw-r--r-- | include/xmloff/PropertySetInfoHash.hxx | 59 | ||||
-rw-r--r-- | include/xmloff/PropertySetInfoKey.hxx | 61 | ||||
-rw-r--r-- | include/xmloff/SinglePropertySetInfoCache.hxx | 21 | ||||
-rw-r--r-- | xmloff/source/style/SinglePropertySetInfoCache.cxx | 51 | ||||
-rw-r--r-- | xmloff/source/style/xmlexppr.cxx | 51 |
5 files changed, 36 insertions, 207 deletions
diff --git a/include/xmloff/PropertySetInfoHash.hxx b/include/xmloff/PropertySetInfoHash.hxx deleted file mode 100644 index 4f987ca8e424..000000000000 --- a/include/xmloff/PropertySetInfoHash.hxx +++ /dev/null @@ -1,59 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ -#ifndef INCLUDED_XMLOFF_PROPERTYSETINFOHASH_HXX -#define INCLUDED_XMLOFF_PROPERTYSETINFOHASH_HXX - -#include <xmloff/PropertySetInfoKey.hxx> - -#include <string.h> -#include <memory> - -struct PropertySetInfoHash -{ - inline size_t operator()( const PropertySetInfoKey& r ) const; - inline bool operator()( const PropertySetInfoKey& r1, - const PropertySetInfoKey& r2 ) const; -}; - -inline size_t PropertySetInfoHash::operator()( - const PropertySetInfoKey& r ) const -{ - const sal_Int32* pBytesAsInt32Array = - (const sal_Int32*)r.aImplementationId.getConstArray(); - sal_Int32 nId32 = pBytesAsInt32Array[0] ^ - pBytesAsInt32Array[1] ^ - pBytesAsInt32Array[2] ^ - pBytesAsInt32Array[3]; - return (size_t)nId32 ^ (size_t)r.xPropInfo.get(); -} - -inline bool PropertySetInfoHash::operator()( - const PropertySetInfoKey& r1, - const PropertySetInfoKey& r2 ) const -{ - if( r1.xPropInfo != r2.xPropInfo ) - return false; - - const sal_Int8* pId1 = r1.aImplementationId.getConstArray(); - const sal_Int8* pId2 = r2.aImplementationId.getConstArray(); - return memcmp( pId1, pId2, 16 * sizeof( sal_Int8 ) ) == 0; -} -#endif - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/xmloff/PropertySetInfoKey.hxx b/include/xmloff/PropertySetInfoKey.hxx deleted file mode 100644 index ab55c74d6b61..000000000000 --- a/include/xmloff/PropertySetInfoKey.hxx +++ /dev/null @@ -1,61 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ -#ifndef INCLUDED_XMLOFF_PROPERTYSETINFOKEY_HXX -#define INCLUDED_XMLOFF_PROPERTYSETINFOKEY_HXX - -#include <osl/diagnose.h> -#include <com/sun/star/uno/Sequence.hxx> - -namespace com { namespace sun { namespace star { - namespace beans { class XPropertySetInfo; } -} } } - - -struct PropertySetInfoKey -{ - ::com::sun::star::uno::Reference < - ::com::sun::star::beans::XPropertySetInfo > xPropInfo; - ::com::sun::star::uno::Sequence < sal_Int8 > aImplementationId; - - inline PropertySetInfoKey(); - inline PropertySetInfoKey( - const ::com::sun::star::uno::Reference < - ::com::sun::star::beans::XPropertySetInfo >& rPropInfo, - const ::com::sun::star::uno::Sequence < sal_Int8 >& rImplId ); -}; - -inline PropertySetInfoKey::PropertySetInfoKey() -{ - OSL_ENSURE( aImplementationId.getLength()==16, "illegal constructor call" ); -} - -inline PropertySetInfoKey::PropertySetInfoKey( - const ::com::sun::star::uno::Reference < - ::com::sun::star::beans::XPropertySetInfo >& rPropInfo, - const ::com::sun::star::uno::Sequence < sal_Int8 >& rImplId ) : - xPropInfo( rPropInfo ), - aImplementationId( rImplId ) -{ - OSL_ENSURE( rPropInfo.is(), "prop info missing" ); - OSL_ENSURE( aImplementationId.getLength()==16, "invalid implementation id" ); -} - -#endif - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/xmloff/SinglePropertySetInfoCache.hxx b/include/xmloff/SinglePropertySetInfoCache.hxx index 55c37aaa8f9d..85ff232be964 100644 --- a/include/xmloff/SinglePropertySetInfoCache.hxx +++ b/include/xmloff/SinglePropertySetInfoCache.hxx @@ -20,23 +20,19 @@ #ifndef INCLUDED_XMLOFF_SINGLEPROPERTYSETINFOCACHE_HXX #define INCLUDED_XMLOFF_SINGLEPROPERTYSETINFOCACHE_HXX -#include <com/sun/star/beans/XPropertySet.hpp> +#include <sal/config.h> -#include <boost/unordered_map.hpp> -#include <xmloff/PropertySetInfoHash.hxx> +#include <map> -typedef boost::unordered_map -< - PropertySetInfoKey, - sal_Bool, - PropertySetInfoHash, - PropertySetInfoHash -> -SinglePropertySetInfoMap_Impl; +#include <com/sun/star/beans/XPropertySet.hpp> -class SinglePropertySetInfoCache : private SinglePropertySetInfoMap_Impl +class SinglePropertySetInfoCache { + typedef std::map<css::uno::Reference<css::beans::XPropertySetInfo>, bool> + Map; + OUString sName; + Map map_; public: @@ -48,6 +44,7 @@ public: ::com::sun::star::beans::XPropertySet >& rPropSet, ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo >& rPropSetInfo ); + inline sal_Bool hasProperty( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet>& rPropSet ); diff --git a/xmloff/source/style/SinglePropertySetInfoCache.cxx b/xmloff/source/style/SinglePropertySetInfoCache.cxx index 701d68685ffe..aa9a0d08c5f3 100644 --- a/xmloff/source/style/SinglePropertySetInfoCache.cxx +++ b/xmloff/source/style/SinglePropertySetInfoCache.cxx @@ -17,12 +17,10 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#include <com/sun/star/lang/XTypeProvider.hpp> #include <cppuhelper/weakref.hxx> #include <xmloff/SinglePropertySetInfoCache.hxx> using namespace ::com::sun::star::uno; -using ::com::sun::star::lang::XTypeProvider; using ::com::sun::star::beans::XPropertySet; using ::com::sun::star::beans::XPropertySetInfo; @@ -32,46 +30,23 @@ sal_Bool SinglePropertySetInfoCache::hasProperty( { if( !rPropSetInfo.is() ) rPropSetInfo = rPropSet->getPropertySetInfo(); - sal_Bool bRet = sal_False, bValid = sal_False; - Reference < XTypeProvider > xTypeProv( rPropSet, UNO_QUERY ); - Sequence< sal_Int8 > aImplId; - if( xTypeProv.is() ) + Map::iterator aIter = map_.find( rPropSetInfo ); + if( aIter != map_.end() ) { - aImplId = xTypeProv->getImplementationId(); - if( aImplId.getLength() == 16 ) - { - // The key must not be created outside this block, because it - // keeps a reference to the property set info. - PropertySetInfoKey aKey( rPropSetInfo, aImplId ); - iterator aIter = find( aKey ); - if( aIter != end() ) - { - bRet = (*aIter).second; - bValid = sal_True; - } - } + return (*aIter).second; } - if( !bValid ) + bool bRet = rPropSetInfo->hasPropertyByName( sName ); + // Check whether the property set info is destroyed if it is assigned to a + // weak reference only; if it is destroyed, then every instance of + // getPropertySetInfo returns a new object; Such property set infos must not + // be cached: + WeakReference < XPropertySetInfo > xWeakInfo( rPropSetInfo ); + rPropSetInfo = 0; + rPropSetInfo = xWeakInfo; + if( rPropSetInfo.is() ) { - bRet = rPropSetInfo->hasPropertyByName( sName ); - if( xTypeProv.is() && aImplId.getLength() == 16 ) - { - // Check whether the property set info is destroyed if it is - // assigned to a weak reference only. If it is destroyed, then - // every instance of getPropertySetInfo returns a new object. - // Such property set infos must not be cached. - WeakReference < XPropertySetInfo > xWeakInfo( rPropSetInfo ); - rPropSetInfo = 0; - rPropSetInfo = xWeakInfo; - if( rPropSetInfo.is() ) - { - PropertySetInfoKey aKey( rPropSetInfo, aImplId ); - value_type aValue( aKey, bRet ); - insert( aValue ); - } - } + map_.insert(Map::value_type(rPropSetInfo, bRet)); } - return bRet; } diff --git a/xmloff/source/style/xmlexppr.cxx b/xmloff/source/style/xmlexppr.cxx index bddd6eb143d2..8c482294032d 100644 --- a/xmloff/source/style/xmlexppr.cxx +++ b/xmloff/source/style/xmlexppr.cxx @@ -21,13 +21,12 @@ #include <com/sun/star/xml/AttributeData.hpp> #include <com/sun/star/beans/XPropertySet.hpp> #include <com/sun/star/beans/XPropertyState.hpp> -#include <com/sun/star/lang/XTypeProvider.hpp> #include <com/sun/star/beans/XMultiPropertySet.hpp> #include <com/sun/star/beans/XTolerantMultiPropertySet.hpp> #include <com/sun/star/beans/TolerantPropertySetResultType.hpp> #include <rtl/ustrbuf.hxx> #include <list> -#include <boost/unordered_map.hpp> +#include <map> #include <xmloff/xmlexppr.hxx> #include <xmloff/xmltoken.hxx> @@ -36,7 +35,6 @@ #include <xmloff/xmlnmspe.hxx> #include <xmloff/xmlexp.hxx> #include <xmloff/xmlprmap.hxx> -#include <xmloff/PropertySetInfoHash.hxx> using namespace ::std; using namespace ::com::sun::star; @@ -510,7 +508,7 @@ void FilterPropertiesInfo_Impl::FillPropertyStateArray( struct SvXMLExportPropertyMapper::Impl { - typedef boost::unordered_map<PropertySetInfoKey, FilterPropertiesInfo_Impl*, PropertySetInfoHash, PropertySetInfoHash> CacheType; + typedef std::map<css::uno::Reference<css::beans::XPropertySetInfo>, FilterPropertiesInfo_Impl*> CacheType; CacheType maCache; UniReference<SvXMLExportPropertyMapper> mxNextMapper; @@ -585,21 +583,9 @@ vector< XMLPropertyState > SvXMLExportPropertyMapper::_Filter( FilterPropertiesInfo_Impl *pFilterInfo = 0; - Reference < XTypeProvider > xTypeProv( xPropSet, UNO_QUERY ); - Sequence< sal_Int8 > aImplId; - if( xTypeProv.is() ) - { - aImplId = xTypeProv->getImplementationId(); - if( aImplId.getLength() == 16 ) - { - // The key must not be created outside this block, because it - // keeps a reference to the property set info. - PropertySetInfoKey aKey( xInfo, aImplId ); - Impl::CacheType::iterator aIter = mpImpl->maCache.find(aKey); - if (aIter != mpImpl->maCache.end()) - pFilterInfo = (*aIter).second; - } - } + Impl::CacheType::iterator aIter = mpImpl->maCache.find(xInfo); + if (aIter != mpImpl->maCache.end()) + pFilterInfo = (*aIter).second; sal_Bool bDelInfo = sal_False; if( !pFilterInfo ) @@ -625,28 +611,19 @@ vector< XMLPropertyState > SvXMLExportPropertyMapper::_Filter( } } - if( xTypeProv.is() && aImplId.getLength() == 16 ) + // Check whether the property set info is destroyed if it is assigned to + // a weak reference only; If it is destroyed, then every instance of + // getPropertySetInfo returns a new object; such property set infos must + // not be cached: + WeakReference < XPropertySetInfo > xWeakInfo( xInfo ); + xInfo = 0; + xInfo = xWeakInfo; + if( xInfo.is() ) { - // Check whether the property set info is destroyed if it is - // assigned to a weak reference only. If it is destroyed, then - // every instance of getPropertySetInfo returns a new object. - // Such property set infos must not be cached. - WeakReference < XPropertySetInfo > xWeakInfo( xInfo ); - xInfo = 0; - xInfo = xWeakInfo; - if( xInfo.is() ) - { - PropertySetInfoKey aKey( xInfo, aImplId ); - mpImpl->maCache.insert(Impl::CacheType::value_type(aKey, pFilterInfo)); - } - else - bDelInfo = true; + mpImpl->maCache.insert(Impl::CacheType::value_type(xInfo, pFilterInfo)); } else - { - OSL_FAIL("here is no TypeProvider or the ImplId is wrong"); bDelInfo = true; - } } if( pFilterInfo->GetPropertyCount() ) |