chart2/source/controller/main/ControllerCommandDispatch.cxx |   57 ++++--------
 1 file changed, 19 insertions(+), 38 deletions(-)

New commits:
commit 51233dfa4adae23b720bf150b0a62b6459f4baf8
Author:     Mike Kaganski <[email protected]>
AuthorDate: Sun Jul 6 20:43:43 2025 +0500
Commit:     Xisco Fauli <[email protected]>
CommitDate: Mon Aug 18 17:05:58 2025 +0200

    tdf#167988: Avoid re-asking the property value, when it has already...
    
    ...been obtained
    
    Change-Id: I0ba8382e8839ca47b86d5ae4671c30006a81441a
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/187447
    Reviewed-by: Mike Kaganski <[email protected]>
    Tested-by: Jenkins
    Signed-off-by: Xisco Fauli <[email protected]>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/189859

diff --git a/chart2/source/controller/main/ControllerCommandDispatch.cxx 
b/chart2/source/controller/main/ControllerCommandDispatch.cxx
index e6abe080a655..a9bb7168df8d 100644
--- a/chart2/source/controller/main/ControllerCommandDispatch.cxx
+++ b/chart2/source/controller/main/ControllerCommandDispatch.cxx
@@ -77,24 +77,22 @@ bool lcl_isStatusBarVisible( const Reference< 
frame::XController > & xController
     return bIsStatusBarVisible;
 }
 
-bool lcl_arePropertiesSame(std::vector<Reference<beans::XPropertySet>>& 
xProperties,
+uno::Any getPropertyIfSame(std::vector<Reference<beans::XPropertySet>>& 
xProperties,
                            const OUString& aPropName)
 {
-    if (xProperties.size() == 1)
-        return true;
     if (xProperties.size() < 1)
-        return false;
+        return {};
 
     if (!xProperties[0])
-        return false;
+        return {};
 
     uno::Any aValue = xProperties[0]->getPropertyValue(aPropName);
     for (std::size_t i = 1; i < xProperties.size(); i++)
     {
         if (xProperties[i] && aValue != 
xProperties[i]->getPropertyValue(aPropName))
-            return false;
+            return {};
     }
-    return true;
+    return aValue;
 }
 
 } // anonymous namespace
@@ -761,64 +759,49 @@ void 
ControllerCommandDispatch::updateCommandAvailability()
 
                 if (!aFont.Name.isEmpty())
                 {
-                    OUString aPropName = u"CharFontName"_ustr;
-                    if (lcl_arePropertiesSame(xProperties, aPropName))
+                    if (getPropertyIfSame(xProperties, 
u"CharFontName"_ustr).hasValue())
                     {
                         m_aCommandArguments[u".uno:CharFontName"_ustr] <<= 
aFont;
                     }
                 }
             }
-            OUString aPropName = u"CharHeight"_ustr;
-            if (lcl_arePropertiesSame(xProperties, aPropName))
+            if (frame::status::FontHeight aFontHeight;
+                getPropertyIfSame(xProperties, u"CharHeight"_ustr) >>= 
aFontHeight.Height)
             {
-                uno::Any aAny = xProperties[0]->getPropertyValue(aPropName);
-                frame::status::FontHeight aFontHeight;
-                aAny >>= aFontHeight.Height;
                 // another type is needed here, so
                 m_aCommandArguments[u".uno:FontHeight"_ustr] <<= aFontHeight;
             }
 
-            aPropName = u"CharWeight"_ustr;
-            if (lcl_arePropertiesSame(xProperties, aPropName))
+            if (float nFontWeight;
+                getPropertyIfSame(xProperties, u"CharWeight"_ustr) >>= 
nFontWeight)
             {
-                float nFontWeight(0.0);
-                xProperties[0]->getPropertyValue(aPropName) >>= nFontWeight;
                 bool bFontWeight = (nFontWeight > 100.0);
                 m_aCommandArguments[u".uno:Bold"_ustr] <<= bFontWeight;
             }
 
-            aPropName = u"CharPosture"_ustr;
-            if (lcl_arePropertiesSame(xProperties, aPropName))
+            if (awt::FontSlant nFontItalic;
+                getPropertyIfSame(xProperties, u"CharPosture"_ustr) >>= 
nFontItalic)
             {
-                awt::FontSlant nFontItalic;
-                xProperties[0]->getPropertyValue(aPropName) >>= nFontItalic;
                 bool bItalic = (nFontItalic == awt::FontSlant_ITALIC);
                 m_aCommandArguments[u".uno:Italic"_ustr] <<= bItalic;
             }
 
-            aPropName = u"CharStrikeout"_ustr;
-            if (lcl_arePropertiesSame(xProperties, aPropName))
+            if (sal_Int16 nFontStrikeout;
+                getPropertyIfSame(xProperties, u"CharStrikeout"_ustr) >>= 
nFontStrikeout)
             {
-                sal_Int16 nFontStrikeout(0);
-                xProperties[0]->getPropertyValue(aPropName) >>= nFontStrikeout;
                 bool bFontStrikeout = (nFontStrikeout > 0);
                 m_aCommandArguments[u".uno:Strikeout"_ustr] <<= bFontStrikeout;
             }
 
-            aPropName = u"CharUnderline"_ustr;
-            if (lcl_arePropertiesSame(xProperties, aPropName))
+            if (sal_Int16 nFontUnderline;
+                getPropertyIfSame(xProperties, u"CharUnderline"_ustr) >>= 
nFontUnderline)
             {
-                sal_Int16 nFontUnderline(0);
-                xProperties[0]->getPropertyValue(aPropName) >>= nFontUnderline;
                 bool bFontUnderline = (nFontUnderline > 0);
                 m_aCommandArguments[u".uno:Underline"_ustr] <<= bFontUnderline;
             }
 
-            aPropName = u"CharShadowed"_ustr;
-            if (lcl_arePropertiesSame(xProperties, aPropName))
+            if (bool bShadowed; getPropertyIfSame(xProperties, 
u"CharShadowed"_ustr) >>= bShadowed)
             {
-                bool bShadowed = false;
-                xProperties[0]->getPropertyValue(aPropName) >>= bShadowed;
                 m_aCommandArguments[u".uno:Shadowed"_ustr] <<= bShadowed;
             }
 
@@ -826,11 +809,9 @@ void ControllerCommandDispatch::updateCommandAvailability()
             m_aCommandArguments[u".uno:Color"_ustr] <<= false;
             m_aCommandArguments[u".uno:FontColor"_ustr] <<= false;
 
-            aPropName = u"CharEscapement"_ustr;
-            if (lcl_arePropertiesSame(xProperties, aPropName))
+            if (sal_Int32 nCharEscapement;
+                getPropertyIfSame(xProperties, u"CharEscapement"_ustr) >>= 
nCharEscapement)
             {
-                sal_Int32 nCharEscapement = 0;
-                xProperties[0]->getPropertyValue(aPropName) >>= 
nCharEscapement;
                 m_aCommandArguments[u".uno:SuperScript"_ustr] <<= 
(nCharEscapement > 0);
                 m_aCommandArguments[u".uno:SubScript"_ustr] <<= 
(nCharEscapement < 0);
             }
commit 20b57f50b1bd6191595d6f3d9a663d04b3b67591
Author:     Justin Luth <[email protected]>
AuthorDate: Fri Jun 27 17:14:56 2025 -0400
Commit:     Xisco Fauli <[email protected]>
CommitDate: Mon Aug 18 17:05:49 2025 +0200

    fix build: chart2 -Werror=maybe-uninitialized
    
    Not sure why only I'm picking this up on Ubuntu 24.04
    gcc (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0
    
    chart2/source/controller/main/ControllerCommandDispatch.cxx:786:49:
    error: ‘nFontWeight’ may be used uninitialized
    [-Werror=maybe-uninitialized]
      786 |                 bool bFontWeight = (nFontWeight > 100.0);
          |                                    ~~~~~~~~~~~~~^~~~~~~~
    libreoffice/chart2/source/controller/main/
    ControllerCommandDispatch.cxx:784:23:
    note: ‘nFontWeight’ was declared here
      784 |                 float nFontWeight;
    
    Added with commit 1160d5b29a9cdae5ec6126663e888b8e5c76aba4
    Author: Attila Szűcs on Thu Apr 24 11:13:08 2025 +0200
        Chart Font sidebar panel
    and commited on May 8.
    
    I'm sure I sucessfully compiled on this machine since May 8,
    but just now I did a make clean and hit this warning.
    I added to autogen.input: --with-distro=LibreOfficeFlatpak
    
    Anyway, now it compiles for me.
    
    Change-Id: I32cd286cdaa607bc4062e9238e9983fd8713f67c
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/187125
    Tested-by: Jenkins
    Reviewed-by: Justin Luth <[email protected]>
    Signed-off-by: Xisco Fauli <[email protected]>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/189858

diff --git a/chart2/source/controller/main/ControllerCommandDispatch.cxx 
b/chart2/source/controller/main/ControllerCommandDispatch.cxx
index 9b1dce5ff6d5..e6abe080a655 100644
--- a/chart2/source/controller/main/ControllerCommandDispatch.cxx
+++ b/chart2/source/controller/main/ControllerCommandDispatch.cxx
@@ -781,7 +781,7 @@ void ControllerCommandDispatch::updateCommandAvailability()
             aPropName = u"CharWeight"_ustr;
             if (lcl_arePropertiesSame(xProperties, aPropName))
             {
-                float nFontWeight;
+                float nFontWeight(0.0);
                 xProperties[0]->getPropertyValue(aPropName) >>= nFontWeight;
                 bool bFontWeight = (nFontWeight > 100.0);
                 m_aCommandArguments[u".uno:Bold"_ustr] <<= bFontWeight;
@@ -799,7 +799,7 @@ void ControllerCommandDispatch::updateCommandAvailability()
             aPropName = u"CharStrikeout"_ustr;
             if (lcl_arePropertiesSame(xProperties, aPropName))
             {
-                sal_Int16 nFontStrikeout;
+                sal_Int16 nFontStrikeout(0);
                 xProperties[0]->getPropertyValue(aPropName) >>= nFontStrikeout;
                 bool bFontStrikeout = (nFontStrikeout > 0);
                 m_aCommandArguments[u".uno:Strikeout"_ustr] <<= bFontStrikeout;
@@ -808,7 +808,7 @@ void ControllerCommandDispatch::updateCommandAvailability()
             aPropName = u"CharUnderline"_ustr;
             if (lcl_arePropertiesSame(xProperties, aPropName))
             {
-                sal_Int16 nFontUnderline;
+                sal_Int16 nFontUnderline(0);
                 xProperties[0]->getPropertyValue(aPropName) >>= nFontUnderline;
                 bool bFontUnderline = (nFontUnderline > 0);
                 m_aCommandArguments[u".uno:Underline"_ustr] <<= bFontUnderline;

Reply via email to