include/toolkit/helper/property.hxx              |    1 
 toolkit/source/helper/property.cxx               |  104 ++++++-----------------
 toolkit/source/helper/unopropertyarrayhelper.cxx |    8 -
 3 files changed, 32 insertions(+), 81 deletions(-)

New commits:
commit 5dba03b200564e2f891fc7e75e948f93ea769c10
Author:     Noel Grandin <[email protected]>
AuthorDate: Sun Apr 9 20:53:12 2023 +0200
Commit:     Noel Grandin <[email protected]>
CommitDate: Mon Apr 10 21:51:58 2023 +0200

    pack the ImplPropertyInfo struct
    
    Change-Id: I08d163824ca0ed4fdba91d1e0d4d7f076c64a4dd
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/150190
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <[email protected]>

diff --git a/toolkit/source/helper/property.cxx 
b/toolkit/source/helper/property.cxx
index 1775ea9cdfcb..315f0ef5d897 100644
--- a/toolkit/source/helper/property.cxx
+++ b/toolkit/source/helper/property.cxx
@@ -52,15 +52,15 @@ namespace {
 
 struct ImplPropertyInfo
 {
-    sal_uInt16               nPropId;
     css::uno::Type           aType;
+    sal_uInt16               nPropId;
     sal_Int16                nAttribs;
     bool                     bDependsOnOthers;   // eg. VALUE depends on 
MIN/MAX and must be set after MIN/MAX.
 
     ImplPropertyInfo( sal_uInt16 nId, const css::uno::Type& rType,
                         sal_Int16 nAttrs, bool bDepends = false )
-         : nPropId(nId)
-         , aType(rType)
+         : aType(rType)
+         , nPropId(nId)
          , nAttribs(nAttrs)
          , bDependsOnOthers(bDepends)
      {
commit 9ff063eeabc38d9c1fd1a4beb0d0e4112559b0c1
Author:     Noel Grandin <[email protected]>
AuthorDate: Sun Apr 9 20:43:29 2023 +0200
Commit:     Noel Grandin <[email protected]>
CommitDate: Mon Apr 10 21:51:49 2023 +0200

    use std::unordered_map for static properties in toolkit
    
    which is faster than binary lookup
    
    Change-Id: Ia810313af36c75fd9b5b241704f0cbd66afcb6b0
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/150189
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <[email protected]>

diff --git a/include/toolkit/helper/property.hxx 
b/include/toolkit/helper/property.hxx
index 92adc587d171..e082433dd364 100644
--- a/include/toolkit/helper/property.hxx
+++ b/include/toolkit/helper/property.hxx
@@ -238,7 +238,6 @@ TOOLKIT_DLLPUBLIC sal_uInt16        GetPropertyId( const 
OUString& rPropertyName
 const css::uno::Type*  GetPropertyType( sal_uInt16 nPropertyId );
 const OUString&        GetPropertyName( sal_uInt16 nPropertyId );
 sal_Int16                           GetPropertyAttribs( sal_uInt16 nPropertyId 
);
-sal_uInt16                          GetPropertyOrderNr( sal_uInt16 nPropertyId 
);
 bool                            DoesDependOnOthers( sal_uInt16 nPropertyId );
 bool                            CompareProperties( const css::uno::Any& r1, 
const css::uno::Any& r2 );
 
diff --git a/toolkit/source/helper/property.cxx 
b/toolkit/source/helper/property.cxx
index f05fee0aea7e..1775ea9cdfcb 100644
--- a/toolkit/source/helper/property.cxx
+++ b/toolkit/source/helper/property.cxx
@@ -36,6 +36,7 @@
 #include <algorithm>
 #include <string_view>
 #include <utility>
+#include <unordered_map>
 
 using ::com::sun::star::uno::Any;
 using ::com::sun::star::uno::Sequence;
@@ -51,16 +52,14 @@ namespace {
 
 struct ImplPropertyInfo
 {
-    OUString                 aName;
     sal_uInt16               nPropId;
     css::uno::Type           aType;
     sal_Int16                nAttribs;
     bool                     bDependsOnOthers;   // eg. VALUE depends on 
MIN/MAX and must be set after MIN/MAX.
 
-    ImplPropertyInfo( OUString theName, sal_uInt16 nId, const css::uno::Type& 
rType,
+    ImplPropertyInfo( sal_uInt16 nId, const css::uno::Type& rType,
                         sal_Int16 nAttrs, bool bDepends = false )
-         : aName(std::move(theName))
-         , nPropId(nId)
+         : nPropId(nId)
          , aType(rType)
          , nAttribs(nAttrs)
          , bDependsOnOthers(bDepends)
@@ -72,20 +71,21 @@ struct ImplPropertyInfo
 }
 
 #define DECL_PROP_1( asciiname, id, type, attrib1 ) \
-    ImplPropertyInfo( asciiname, BASEPROPERTY_##id, 
cppu::UnoType<type>::get(), css::beans::PropertyAttribute::attrib1 )
+    { asciiname, ImplPropertyInfo( BASEPROPERTY_##id, 
cppu::UnoType<type>::get(), css::beans::PropertyAttribute::attrib1 ) }
 #define DECL_PROP_2( asciiname, id, type, attrib1, attrib2 ) \
-    ImplPropertyInfo( asciiname, BASEPROPERTY_##id, 
cppu::UnoType<type>::get(), css::beans::PropertyAttribute::attrib1 | 
css::beans::PropertyAttribute::attrib2 )
+    { asciiname, ImplPropertyInfo( BASEPROPERTY_##id, 
cppu::UnoType<type>::get(), css::beans::PropertyAttribute::attrib1 | 
css::beans::PropertyAttribute::attrib2 ) }
 #define DECL_PROP_3( asciiname, id, type, attrib1, attrib2, attrib3 ) \
-    ImplPropertyInfo( asciiname, BASEPROPERTY_##id, 
cppu::UnoType<type>::get(), css::beans::PropertyAttribute::attrib1 | 
css::beans::PropertyAttribute::attrib2 | css::beans::PropertyAttribute::attrib3 
)
+    { asciiname, ImplPropertyInfo( BASEPROPERTY_##id, 
cppu::UnoType<type>::get(), css::beans::PropertyAttribute::attrib1 | 
css::beans::PropertyAttribute::attrib2 | css::beans::PropertyAttribute::attrib3 
) }
 
 #define DECL_DEP_PROP_2( asciiname, id, type, attrib1, attrib2 ) \
-    ImplPropertyInfo( asciiname, BASEPROPERTY_##id, 
cppu::UnoType<type>::get(), css::beans::PropertyAttribute::attrib1 | 
css::beans::PropertyAttribute::attrib2, true )
+    { asciiname, ImplPropertyInfo( BASEPROPERTY_##id, 
cppu::UnoType<type>::get(), css::beans::PropertyAttribute::attrib1 | 
css::beans::PropertyAttribute::attrib2, true ) }
 #define DECL_DEP_PROP_3( asciiname, id, type, attrib1, attrib2, attrib3 ) \
-    ImplPropertyInfo( asciiname, BASEPROPERTY_##id, 
cppu::UnoType<type>::get(), css::beans::PropertyAttribute::attrib1 | 
css::beans::PropertyAttribute::attrib2 | 
css::beans::PropertyAttribute::attrib3, true )
+    { asciiname, ImplPropertyInfo( BASEPROPERTY_##id, 
cppu::UnoType<type>::get(), css::beans::PropertyAttribute::attrib1 | 
css::beans::PropertyAttribute::attrib2 | 
css::beans::PropertyAttribute::attrib3, true ) }
 
-static ImplPropertyInfo* ImplGetPropertyInfos( sal_uInt16& rElementCount )
+typedef std::unordered_map<OUString, ImplPropertyInfo> ImpPropertyInfoMap;
+static const ImpPropertyInfoMap & ImplGetPropertyInfos()
 {
-    static ImplPropertyInfo aImplPropertyInfos [] = {
+    static const ImpPropertyInfoMap aImplPropertyInfos {
         DECL_PROP_2     ( "AccessibleName",         ACCESSIBLENAME,         
OUString,       BOUND, MAYBEDEFAULT ),
         DECL_PROP_3     ( "Align",                  ALIGN,                  
sal_Int16,      BOUND, MAYBEDEFAULT, MAYBEVOID ),
         DECL_PROP_2     ( "Autocomplete",           AUTOCOMPLETE,           
bool,           BOUND, MAYBEDEFAULT ),
@@ -272,85 +272,37 @@ static ImplPropertyInfo* ImplGetPropertyInfos( 
sal_uInt16& rElementCount )
         DECL_PROP_3     ( "ActiveSelectionTextColor",         
ACTIVE_SEL_TEXT_COLOR,         sal_Int32, BOUND, MAYBEDEFAULT, MAYBEVOID ),
         DECL_PROP_3     ( "InactiveSelectionTextColor",       
INACTIVE_SEL_TEXT_COLOR,       sal_Int32, BOUND, MAYBEDEFAULT, MAYBEVOID ),
     };
-    rElementCount = SAL_N_ELEMENTS(aImplPropertyInfos);
     return aImplPropertyInfos;
 }
 
-namespace {
-
-struct ImplPropertyInfoCompareFunctor
-{
-    bool operator()(const ImplPropertyInfo& lhs,const ImplPropertyInfo& rhs) 
const
-    {
-        return lhs.aName.compareTo(rhs.aName) < 0;
-    }
-    bool operator()(const ImplPropertyInfo& lhs,std::u16string_view rhs)  const
-    {
-        return lhs.aName.compareTo(rhs) < 0;
-    }
-};
-
-}
-
-static void ImplAssertValidPropertyArray()
-{
-    static bool bSorted = false;
-    if( !bSorted )
-    {
-        sal_uInt16 nElements;
-        ImplPropertyInfo* pInfo = ImplGetPropertyInfos( nElements );
-        ::std::sort(pInfo, pInfo+nElements,ImplPropertyInfoCompareFunctor());
-        bSorted = true;
-    }
-}
-
 sal_uInt16 GetPropertyId( const OUString& rPropertyName )
 {
-    ImplAssertValidPropertyArray();
-
-    sal_uInt16 nElements;
-    ImplPropertyInfo* pInfo = ImplGetPropertyInfos( nElements );
-    ImplPropertyInfo* pInf = 
::std::lower_bound(pInfo,pInfo+nElements,rPropertyName,ImplPropertyInfoCompareFunctor());
-/*
-        (ImplPropertyInfo*)
-                                bsearch( &aSearch, pInfo, nElements, sizeof( 
ImplPropertyInfo ), ImplPropertyInfoCompare );
-*/
-
-    return ( pInf && pInf != (pInfo+nElements) && pInf->aName == 
rPropertyName) ? pInf->nPropId: 0;
+    const ImpPropertyInfoMap & rMap = ImplGetPropertyInfos();
+    auto it = rMap.find(rPropertyName);
+    return it != rMap.end() ? it->second.nPropId : 0;
 }
 
 static const ImplPropertyInfo* ImplGetImplPropertyInfo( sal_uInt16 nPropertyId 
)
 {
-    ImplAssertValidPropertyArray();
+    const ImpPropertyInfoMap & rMap = ImplGetPropertyInfos();
 
-    sal_uInt16 nElements;
-    ImplPropertyInfo* pInfo = ImplGetPropertyInfos( nElements );
-    sal_uInt16 n;
-    for ( n = 0; n < nElements && pInfo[n].nPropId != nPropertyId; ++n)
-        ;
-
-    return (n < nElements) ? &pInfo[n] : nullptr;
+    for (auto const & rPair : rMap)
+        if (rPair.second.nPropId == nPropertyId)
+            return &rPair.second;
+    return nullptr;
 }
 
-sal_uInt16 GetPropertyOrderNr( sal_uInt16 nPropertyId )
+const OUString& GetPropertyName( sal_uInt16 nPropertyId )
 {
-    ImplAssertValidPropertyArray();
+    const ImpPropertyInfoMap & rMap = ImplGetPropertyInfos();
 
-    sal_uInt16 nElements;
-    ImplPropertyInfo* pInfo = ImplGetPropertyInfos( nElements );
-    for ( sal_uInt16 n = nElements; n; )
-    {
-        if ( pInfo[--n].nPropId == nPropertyId )
-            return n;
-    }
-    return 0xFFFF;
-}
+    for (auto const & rPair : rMap)
+        if (rPair.second.nPropId == nPropertyId)
+            return rPair.first;
 
-const OUString& GetPropertyName( sal_uInt16 nPropertyId )
-{
-    const ImplPropertyInfo* pImplPropertyInfo = ImplGetImplPropertyInfo( 
nPropertyId );
-    assert(pImplPropertyInfo && "Invalid PropertyId!");
-    return pImplPropertyInfo->aName;
+    assert(false && "Invalid PropertyId!");
+    static const OUString EMPTY;
+    return EMPTY;
 }
 
 const css::uno::Type* GetPropertyType( sal_uInt16 nPropertyId )
diff --git a/toolkit/source/helper/unopropertyarrayhelper.cxx 
b/toolkit/source/helper/unopropertyarrayhelper.cxx
index 0a36f4bf31a7..0b4b8055c226 100644
--- a/toolkit/source/helper/unopropertyarrayhelper.cxx
+++ b/toolkit/source/helper/unopropertyarrayhelper.cxx
@@ -64,17 +64,17 @@ css::uno::Sequence< css::beans::Property > 
UnoPropertyArrayHelper::getProperties
 {
     // Sort by names ...
 
-    std::map<sal_Int32, sal_uInt16> aSortedPropsIds;
+    std::map<OUString, sal_uInt16> aSortedPropsIds;
     for (const auto& rId : maIDs)
     {
         sal_uInt16 nId = sal::static_int_cast< sal_uInt16 >(rId);
-        aSortedPropsIds[ 1+GetPropertyOrderNr( nId ) ] = nId;
+        aSortedPropsIds.emplace(GetPropertyName( nId ), nId);
 
         if ( nId == BASEPROPERTY_FONTDESCRIPTOR )
         {
             // single properties ...
             for ( sal_uInt16 i = BASEPROPERTY_FONTDESCRIPTORPART_START; i <= 
BASEPROPERTY_FONTDESCRIPTORPART_END; i++ )
-                aSortedPropsIds[ 1+GetPropertyOrderNr( i ) ]  = i;
+                aSortedPropsIds.emplace(GetPropertyName( i ), i);
         }
     }
 
@@ -86,7 +86,7 @@ css::uno::Sequence< css::beans::Property > 
UnoPropertyArrayHelper::getProperties
     for ( const auto& rPropIds : aSortedPropsIds )
     {
         sal_uInt16 nId = rPropIds.second;
-        pProps[n].Name = GetPropertyName( nId );
+        pProps[n].Name = rPropIds.first;
         pProps[n].Handle = nId;
         pProps[n].Type = *GetPropertyType( nId );
         pProps[n].Attributes = GetPropertyAttribs( nId );

Reply via email to