[Libreoffice-commits] core.git: include/svl svl/source

Noel Grandin (via logerrit) logerrit at kemper.freedesktop.org
Mon May 10 19:19:50 UTC 2021


 include/svl/itemprop.hxx      |   11 ++++++++-
 svl/source/items/itemprop.cxx |   48 +++++++++++++++++++++++++++++-------------
 2 files changed, 44 insertions(+), 15 deletions(-)

New commits:
commit 1820db814909643df22bcb24ba28495adb87fe70
Author:     Noel Grandin <noel at peralex.com>
AuthorDate: Mon May 10 15:22:46 2021 +0200
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Mon May 10 21:19:13 2021 +0200

    speed up SfxExtItemPropertySetInfo
    
    Change-Id: I7fdf0395c40f1932cfa1fc6ada91accc1912851a
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/115352
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/include/svl/itemprop.hxx b/include/svl/itemprop.hxx
index 7be78d1a0330..c6f6b9bd1425 100644
--- a/include/svl/itemprop.hxx
+++ b/include/svl/itemprop.hxx
@@ -202,6 +202,14 @@ public:
 
 };
 
+struct SfxItemPropertyMapCompare2
+{
+    bool operator() ( const SfxItemPropertyMapEntry & lhs, const SfxItemPropertyMapEntry & rhs ) const
+    {
+        return lhs.aName < rhs.aName;
+    }
+};
+
 // workaround for incremental linking bugs in MSVC2015
 class SAL_DLLPUBLIC_TEMPLATE SfxExtItemPropertySetInfo_Base : public cppu::WeakImplHelper< css::beans::XPropertySetInfo > {};
 
@@ -223,7 +231,8 @@ public:
         hasPropertyByName( const OUString& Name ) override;
 
 private:
-    std::unordered_map<OUString, SfxItemPropertySimpleEntry> maMap;
+    const SfxItemPropertyMapEntry* getByName( std::u16string_view rName ) const;
+    o3tl::sorted_vector< SfxItemPropertyMapEntry, SfxItemPropertyMapCompare2 > maMap;
     mutable css::uno::Sequence< css::beans::Property > m_aPropSeq;
 };
 
diff --git a/svl/source/items/itemprop.cxx b/svl/source/items/itemprop.cxx
index 1c4f2ffb8465..1bb49d191007 100644
--- a/svl/source/items/itemprop.cxx
+++ b/svl/source/items/itemprop.cxx
@@ -273,18 +273,21 @@ sal_Bool SAL_CALL SfxItemPropertySetInfo::hasPropertyByName( const OUString& rNa
 SfxExtItemPropertySetInfo::SfxExtItemPropertySetInfo( const SfxItemPropertyMapEntry *pEntries,
                                                       const Sequence<Property>& rPropSeq )
 {
+    maMap.reserve(16);
     while( !pEntries->aName.isEmpty() )
     {
-        maMap.emplace( pEntries->aName, *pEntries );
+        maMap.insert( *pEntries );
         ++pEntries;
     }
     for( const auto & rProp : rPropSeq )
     {
-        SfxItemPropertySimpleEntry aTemp(
+        SfxItemPropertyMapEntry aTemp(
+            rProp.Name,
             sal::static_int_cast< sal_Int16 >( rProp.Handle ), //nWID
             rProp.Type, //aType
-            rProp.Attributes); //nFlags
-        maMap[rProp.Name] = aTemp;
+            rProp.Attributes,
+            0); //nFlags
+        maMap.insert( aTemp );
     }
 }
 
@@ -299,10 +302,9 @@ Sequence< Property > SAL_CALL SfxExtItemPropertySetInfo::getProperties(  )
         m_aPropSeq.realloc( maMap.size() );
         beans::Property* pPropArray = m_aPropSeq.getArray();
         sal_uInt32 n = 0;
-        for( const auto& rPair : maMap )
+        for( const SfxItemPropertyMapEntry& rEntry : maMap )
         {
-            const SfxItemPropertySimpleEntry& rEntry = rPair.second;
-            pPropArray[n].Name = rPair.first;
+            pPropArray[n].Name = rEntry.aName;
             pPropArray[n].Handle = rEntry.nWID;
             pPropArray[n].Type = rEntry.aType;
             pPropArray[n].Attributes =
@@ -316,21 +318,39 @@ Sequence< Property > SAL_CALL SfxExtItemPropertySetInfo::getProperties(  )
 
 Property SAL_CALL SfxExtItemPropertySetInfo::getPropertyByName( const OUString& rPropertyName )
 {
-    auto aIter = maMap.find(rPropertyName);
-    if( aIter == maMap.end() )
+    const SfxItemPropertyMapEntry* pEntry = getByName(rPropertyName);
+    if( !pEntry )
         throw UnknownPropertyException(rPropertyName);
-    const SfxItemPropertySimpleEntry& rEntry = aIter->second;
     beans::Property aProp;
     aProp.Name = rPropertyName;
-    aProp.Handle = rEntry.nWID;
-    aProp.Type = rEntry.aType;
-    aProp.Attributes = sal::static_int_cast< sal_Int16 >(rEntry.nFlags);
+    aProp.Handle = pEntry->nWID;
+    aProp.Type = pEntry->aType;
+    aProp.Attributes = sal::static_int_cast< sal_Int16 >(pEntry->nFlags);
     return aProp;
 }
 
 sal_Bool SAL_CALL SfxExtItemPropertySetInfo::hasPropertyByName( const OUString& rPropertyName )
 {
-    return maMap.find(rPropertyName) != maMap.end();
+    return getByName(rPropertyName) != nullptr;
+}
+
+const SfxItemPropertyMapEntry* SfxExtItemPropertySetInfo::getByName( std::u16string_view rName ) const
+{
+    struct Compare
+    {
+        bool operator() ( const SfxItemPropertyMapEntry& lhs, std::u16string_view rhs ) const
+        {
+            return lhs.aName < rhs;
+        }
+        bool operator() ( std::u16string_view lhs, const SfxItemPropertyMapEntry& rhs ) const
+        {
+            return lhs < rhs.aName;
+        }
+    };
+    auto it = std::lower_bound(maMap.begin(), maMap.end(), rName, Compare());
+    if (it == maMap.end() || Compare()(rName, *it))
+        return nullptr;
+    return &*it;
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */


More information about the Libreoffice-commits mailing list