[Libreoffice-commits] core.git: vcl/source

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Tue Mar 5 13:50:42 UTC 2019


 vcl/source/gdi/WidgetDefinitionReader.cxx |   43 ++++++++----------------------
 1 file changed, 12 insertions(+), 31 deletions(-)

New commits:
commit 4b6e00f08afb2968a1a5731729fc266b0e708ab2
Author:     Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
AuthorDate: Tue Feb 19 13:55:00 2019 +0100
Commit:     Tomaž Vajngerl <quikee at gmail.com>
CommitDate: Tue Mar 5 14:50:15 2019 +0100

    Use a unordered_map for mapping of xml element to control type
    
    Change-Id: Id0409f35a21307ed41a0da27c625c4b7784811d6
    Reviewed-on: https://gerrit.libreoffice.org/68718
    Tested-by: Jenkins
    Reviewed-by: Tomaž Vajngerl <quikee at gmail.com>

diff --git a/vcl/source/gdi/WidgetDefinitionReader.cxx b/vcl/source/gdi/WidgetDefinitionReader.cxx
index 51b07f0ba6fe..799b3dda6187 100644
--- a/vcl/source/gdi/WidgetDefinitionReader.cxx
+++ b/vcl/source/gdi/WidgetDefinitionReader.cxx
@@ -132,39 +132,20 @@ ControlPart xmlStringToControlPart(OString const& sPart)
 
 bool getControlTypeForXmlString(OString const& rString, ControlType& reType)
 {
-    bool bReturn = false;
-    if (rString == "pushbutton")
-    {
-        reType = ControlType::Pushbutton;
-        bReturn = true;
-    }
-    else if (rString == "radiobutton")
-    {
-        reType = ControlType::Radiobutton;
-        bReturn = true;
-    }
-    else if (rString == "editbox")
-    {
-        reType = ControlType::Editbox;
-        bReturn = true;
-    }
-    else if (rString == "checkbox")
-    {
-        reType = ControlType::Checkbox;
-        bReturn = true;
-    }
-    else if (rString == "combobox")
-    {
-        reType = ControlType::Combobox;
-        bReturn = true;
-    }
-    else if (rString == "spinbox")
+    static std::unordered_map<OString, ControlType> aPartMap = {
+        { "pushbutton", ControlType::Pushbutton }, { "radiobutton", ControlType::Radiobutton },
+        { "checkbox", ControlType::Checkbox },     { "combobox", ControlType::Combobox },
+        { "editbox", ControlType::Editbox },       { "scrollbar", ControlType::Scrollbar },
+        { "spinbox", ControlType::Spinbox },
+    };
+
+    auto const& rIterator = aPartMap.find(rString);
+    if (rIterator != aPartMap.end())
     {
-        reType = ControlType::Spinbox;
-        bReturn = true;
+        reType = rIterator->second;
+        return true;
     }
-
-    return bReturn;
+    return false;
 }
 
 } // end anonymous namespace


More information about the Libreoffice-commits mailing list