Kaydet (Commit) db5c67e1 authored tarafından Stephan Bergmann's avatar Stephan Bergmann

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
üst f351fd1e
/* -*- 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: */
/* -*- 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: */
...@@ -20,23 +20,19 @@ ...@@ -20,23 +20,19 @@
#ifndef INCLUDED_XMLOFF_SINGLEPROPERTYSETINFOCACHE_HXX #ifndef INCLUDED_XMLOFF_SINGLEPROPERTYSETINFOCACHE_HXX
#define 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 <map>
#include <xmloff/PropertySetInfoHash.hxx>
typedef boost::unordered_map #include <com/sun/star/beans/XPropertySet.hpp>
<
PropertySetInfoKey,
sal_Bool,
PropertySetInfoHash,
PropertySetInfoHash
>
SinglePropertySetInfoMap_Impl;
class SinglePropertySetInfoCache : private SinglePropertySetInfoMap_Impl class SinglePropertySetInfoCache
{ {
typedef std::map<css::uno::Reference<css::beans::XPropertySetInfo>, bool>
Map;
OUString sName; OUString sName;
Map map_;
public: public:
...@@ -48,6 +44,7 @@ public: ...@@ -48,6 +44,7 @@ public:
::com::sun::star::beans::XPropertySet >& rPropSet, ::com::sun::star::beans::XPropertySet >& rPropSet,
::com::sun::star::uno::Reference< ::com::sun::star::uno::Reference<
::com::sun::star::beans::XPropertySetInfo >& rPropSetInfo ); ::com::sun::star::beans::XPropertySetInfo >& rPropSetInfo );
inline sal_Bool hasProperty( inline sal_Bool hasProperty(
const ::com::sun::star::uno::Reference< const ::com::sun::star::uno::Reference<
::com::sun::star::beans::XPropertySet>& rPropSet ); ::com::sun::star::beans::XPropertySet>& rPropSet );
......
...@@ -17,12 +17,10 @@ ...@@ -17,12 +17,10 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 . * the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/ */
#include <com/sun/star/lang/XTypeProvider.hpp>
#include <cppuhelper/weakref.hxx> #include <cppuhelper/weakref.hxx>
#include <xmloff/SinglePropertySetInfoCache.hxx> #include <xmloff/SinglePropertySetInfoCache.hxx>
using namespace ::com::sun::star::uno; using namespace ::com::sun::star::uno;
using ::com::sun::star::lang::XTypeProvider;
using ::com::sun::star::beans::XPropertySet; using ::com::sun::star::beans::XPropertySet;
using ::com::sun::star::beans::XPropertySetInfo; using ::com::sun::star::beans::XPropertySetInfo;
...@@ -32,46 +30,23 @@ sal_Bool SinglePropertySetInfoCache::hasProperty( ...@@ -32,46 +30,23 @@ sal_Bool SinglePropertySetInfoCache::hasProperty(
{ {
if( !rPropSetInfo.is() ) if( !rPropSetInfo.is() )
rPropSetInfo = rPropSet->getPropertySetInfo(); rPropSetInfo = rPropSet->getPropertySetInfo();
sal_Bool bRet = sal_False, bValid = sal_False; Map::iterator aIter = map_.find( rPropSetInfo );
Reference < XTypeProvider > xTypeProv( rPropSet, UNO_QUERY ); if( aIter != map_.end() )
Sequence< sal_Int8 > aImplId;
if( xTypeProv.is() )
{ {
aImplId = xTypeProv->getImplementationId(); return (*aIter).second;
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;
}
}
} }
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 ); map_.insert(Map::value_type(rPropSetInfo, bRet));
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 );
}
}
} }
return bRet; return bRet;
} }
......
...@@ -21,13 +21,12 @@ ...@@ -21,13 +21,12 @@
#include <com/sun/star/xml/AttributeData.hpp> #include <com/sun/star/xml/AttributeData.hpp>
#include <com/sun/star/beans/XPropertySet.hpp> #include <com/sun/star/beans/XPropertySet.hpp>
#include <com/sun/star/beans/XPropertyState.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/XMultiPropertySet.hpp>
#include <com/sun/star/beans/XTolerantMultiPropertySet.hpp> #include <com/sun/star/beans/XTolerantMultiPropertySet.hpp>
#include <com/sun/star/beans/TolerantPropertySetResultType.hpp> #include <com/sun/star/beans/TolerantPropertySetResultType.hpp>
#include <rtl/ustrbuf.hxx> #include <rtl/ustrbuf.hxx>
#include <list> #include <list>
#include <boost/unordered_map.hpp> #include <map>
#include <xmloff/xmlexppr.hxx> #include <xmloff/xmlexppr.hxx>
#include <xmloff/xmltoken.hxx> #include <xmloff/xmltoken.hxx>
...@@ -36,7 +35,6 @@ ...@@ -36,7 +35,6 @@
#include <xmloff/xmlnmspe.hxx> #include <xmloff/xmlnmspe.hxx>
#include <xmloff/xmlexp.hxx> #include <xmloff/xmlexp.hxx>
#include <xmloff/xmlprmap.hxx> #include <xmloff/xmlprmap.hxx>
#include <xmloff/PropertySetInfoHash.hxx>
using namespace ::std; using namespace ::std;
using namespace ::com::sun::star; using namespace ::com::sun::star;
...@@ -510,7 +508,7 @@ void FilterPropertiesInfo_Impl::FillPropertyStateArray( ...@@ -510,7 +508,7 @@ void FilterPropertiesInfo_Impl::FillPropertyStateArray(
struct SvXMLExportPropertyMapper::Impl 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; CacheType maCache;
UniReference<SvXMLExportPropertyMapper> mxNextMapper; UniReference<SvXMLExportPropertyMapper> mxNextMapper;
...@@ -585,21 +583,9 @@ vector< XMLPropertyState > SvXMLExportPropertyMapper::_Filter( ...@@ -585,21 +583,9 @@ vector< XMLPropertyState > SvXMLExportPropertyMapper::_Filter(
FilterPropertiesInfo_Impl *pFilterInfo = 0; FilterPropertiesInfo_Impl *pFilterInfo = 0;
Reference < XTypeProvider > xTypeProv( xPropSet, UNO_QUERY ); Impl::CacheType::iterator aIter = mpImpl->maCache.find(xInfo);
Sequence< sal_Int8 > aImplId; if (aIter != mpImpl->maCache.end())
if( xTypeProv.is() ) pFilterInfo = (*aIter).second;
{
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;
}
}
sal_Bool bDelInfo = sal_False; sal_Bool bDelInfo = sal_False;
if( !pFilterInfo ) if( !pFilterInfo )
...@@ -625,28 +611,19 @@ vector< XMLPropertyState > SvXMLExportPropertyMapper::_Filter( ...@@ -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 mpImpl->maCache.insert(Impl::CacheType::value_type(xInfo, pFilterInfo));
// 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;
} }
else else
{
OSL_FAIL("here is no TypeProvider or the ImplId is wrong");
bDelInfo = true; bDelInfo = true;
}
} }
if( pFilterInfo->GetPropertyCount() ) if( pFilterInfo->GetPropertyCount() )
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment