diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2022-05-23 13:30:58 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2022-05-24 14:02:09 +0200 |
commit | 912b8fa62f897fb6fdfd760108d87c4dd468b8ee (patch) | |
tree | 963e227f85d29c6cbddff0a1920ad767a8cdeb8c /comphelper | |
parent | ec062c472ad58eafbb4392241119d5b53760120c (diff) |
modernize and improve PropertySetInfo
(*) use o3tl::span for the array param, which means we don't need a null
entry to terminate the array
(*) use std::unordered_map to speed things up
(*) mark the array as static at a few more call sites
Change-Id: I05b6cae7552f44459e183ec05cb94e60edb3bfe0
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/134832
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'comphelper')
-rw-r--r-- | comphelper/source/property/propertysetinfo.cxx | 56 |
1 files changed, 29 insertions, 27 deletions
diff --git a/comphelper/source/property/propertysetinfo.cxx b/comphelper/source/property/propertysetinfo.cxx index 919198772932..6385965c0d56 100644 --- a/comphelper/source/property/propertysetinfo.cxx +++ b/comphelper/source/property/propertysetinfo.cxx @@ -28,63 +28,65 @@ using namespace ::com::sun::star::uno; using namespace ::com::sun::star::beans; using namespace ::com::sun::star::lang; -void PropertySetInfo::addImpl(PropertyMapEntry const * pMap) noexcept -{ - while (!pMap->maName.isEmpty()) - { - // check for duplicates - assert(maPropertyMap.find(pMap->maName) == maPropertyMap.end()); - - maPropertyMap[pMap->maName] = pMap; - - maProperties.realloc(0); - - ++pMap; - } -} - PropertySetInfo::PropertySetInfo() noexcept { } -PropertySetInfo::PropertySetInfo( PropertyMapEntry const * pMap ) noexcept +PropertySetInfo::PropertySetInfo( o3tl::span<const PropertyMapEntry> pMap ) noexcept { - while (!pMap->maName.isEmpty()) + maPropertyMap.reserve(pMap.size()); + for (const auto & rEntry : pMap) { // check for duplicates - assert(maPropertyMap.find(pMap->maName) == maPropertyMap.end()); - - maPropertyMap[pMap->maName] = pMap; + assert(maPropertyMap.find(rEntry.maName) == maPropertyMap.end()); + // Make sure there are no accidental empty entries left at the end of the array from + // when this method used to take a empty-terminated array. + assert(!rEntry.maName.isEmpty()); - ++pMap; + maPropertyMap.emplace(rEntry.maName, &rEntry); } } PropertySetInfo::PropertySetInfo(uno::Sequence<beans::Property> const& rProps) noexcept { - PropertyMapEntry * pEntries(new PropertyMapEntry[rProps.getLength() + 1]); + PropertyMapEntry * pEntries(new PropertyMapEntry[rProps.getLength()]); PropertyMapEntry * pEntry(&pEntries[0]); for (auto const& it : rProps) { + // check for duplicates + assert(maPropertyMap.find(it.Name) == maPropertyMap.end()); + pEntry->maName = it.Name; pEntry->mnHandle = it.Handle; pEntry->maType = it.Type; pEntry->mnAttributes = it.Attributes; pEntry->mnMemberId = 0; + + maPropertyMap.emplace(it.Name, pEntry); ++pEntry; } - pEntry->maName = OUString(); - - addImpl(pEntries); } PropertySetInfo::~PropertySetInfo() noexcept { } -void PropertySetInfo::add( PropertyMapEntry const * pMap ) noexcept +void PropertySetInfo::add( o3tl::span<PropertyMapEntry const> pMap ) noexcept { - addImpl( pMap ); + maPropertyMap.reserve(maPropertyMap.size() + pMap.size()); + for (const auto & rEntry : pMap) + { + // check for duplicates + assert(maPropertyMap.find(rEntry.maName) == maPropertyMap.end()); + // Make sure there are no accidental empty entries left at the end of the array from + // when this method used to take a empty-terminated array. + assert(!rEntry.maName.isEmpty()); + + maPropertyMap.emplace(rEntry.maName, &rEntry); + } + + // clear cache + maProperties.realloc(0); } void PropertySetInfo::remove( const OUString& aName ) noexcept |