diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2018-10-09 16:27:11 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2018-10-22 12:47:37 +0200 |
commit | 76dd28afc9c0eb632a5dd20eb51704ee0bbc4b58 (patch) | |
tree | 82c51d09721476a1a6fcbf1e4cd4af8189ac55a2 /toolkit | |
parent | 78490b45c771a4c9632b324922f2c8e83f06153b (diff) |
loplugin:staticvar in various
looks for variables that can be declared const and static i.e. they can
be stored in the read-only linker segment and shared between different
processes
Change-Id: I8ddc6e5fa0f6b10d80c75d5952df8ddd311cf892
Reviewed-on: https://gerrit.libreoffice.org/61591
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'toolkit')
-rw-r--r-- | toolkit/source/awt/vclxtoolkit.cxx | 178 | ||||
-rw-r--r-- | toolkit/source/helper/vclunohelper.cxx | 8 |
2 files changed, 91 insertions, 95 deletions
diff --git a/toolkit/source/awt/vclxtoolkit.cxx b/toolkit/source/awt/vclxtoolkit.cxx index 7632a50005c2..622a2981e73a 100644 --- a/toolkit/source/awt/vclxtoolkit.cxx +++ b/toolkit/source/awt/vclxtoolkit.cxx @@ -687,87 +687,89 @@ std::pair<WinBits,MessBoxStyle> ImplGetWinBits( sal_uInt32 nComponentAttribs, Wi struct ComponentInfo { - const char* pName; + OUStringLiteral sName; WindowType nWinType; }; -static ComponentInfo aComponentInfos [] = -{ - { "buttondialog", WindowType::BUTTONDIALOG }, - { "cancelbutton", WindowType::CANCELBUTTON }, - { "checkbox", WindowType::CHECKBOX }, - { "combobox", WindowType::COMBOBOX }, - { "control", WindowType::CONTROL }, - { "currencybox", WindowType::CURRENCYBOX }, - { "currencyfield", WindowType::CURRENCYFIELD }, - { "datebox", WindowType::DATEBOX }, - { "datefield", WindowType::DATEFIELD }, - { "dialog", WindowType::DIALOG }, - { "dockingarea", WindowType::DOCKINGAREA }, - { "dockingwindow", WindowType::DOCKINGWINDOW }, - { "edit", WindowType::EDIT }, - { "errorbox", WindowType::ERRORBOX }, - { "fixedbitmap", WindowType::FIXEDBITMAP }, - { "fixedimage", WindowType::FIXEDIMAGE }, - { "fixedline", WindowType::FIXEDLINE }, - { "fixedtext", WindowType::FIXEDTEXT }, - { "floatingwindow", WindowType::FLOATINGWINDOW }, - { "framewindow", WindowType::TOOLKIT_FRAMEWINDOW }, - { "groupbox", WindowType::GROUPBOX }, - { "frame", WindowType::GROUPBOX }, - { "helpbutton", WindowType::HELPBUTTON }, - { "imagebutton", WindowType::IMAGEBUTTON }, - { "infobox", WindowType::INFOBOX }, - { "listbox", WindowType::LISTBOX }, - { "longcurrencybox", WindowType::LONGCURRENCYBOX }, - { "longcurrencyfield", WindowType::LONGCURRENCYFIELD }, - { "menubutton", WindowType::MENUBUTTON }, - { "messbox", WindowType::MESSBOX }, - { "metricbox", WindowType::METRICBOX }, - { "metricfield", WindowType::METRICFIELD }, - { "modaldialog", WindowType::MODALDIALOG }, - { "modelessdialog", WindowType::MODELESSDIALOG }, - { "morebutton", WindowType::MOREBUTTON }, - { "multilineedit", WindowType::MULTILINEEDIT }, - { "multilistbox", WindowType::MULTILISTBOX }, - { "numericbox", WindowType::NUMERICBOX }, - { "numericfield", WindowType::NUMERICFIELD }, - { "okbutton", WindowType::OKBUTTON }, - { "patternbox", WindowType::PATTERNBOX }, - { "patternfield", WindowType::PATTERNFIELD }, - { "pushbutton", WindowType::PUSHBUTTON }, - { "querybox", WindowType::QUERYBOX }, - { "radiobutton", WindowType::RADIOBUTTON }, - { "scrollbar", WindowType::SCROLLBAR }, - { "scrollbarbox", WindowType::SCROLLBARBOX }, - { "animatedimages", WindowType::CONTROL }, - { "spinbutton", WindowType::SPINBUTTON }, - { "spinfield", WindowType::SPINFIELD }, - { "splitter", WindowType::SPLITTER }, - { "splitwindow", WindowType::SPLITWINDOW }, - { "statusbar", WindowType::STATUSBAR }, - { "systemchildwindow", WindowType::TOOLKIT_SYSTEMCHILDWINDOW }, - { "tabcontrol", WindowType::TABCONTROL }, - { "tabdialog", WindowType::TABDIALOG }, - { "tabpage", WindowType::TABPAGE }, - { "timebox", WindowType::TIMEBOX }, - { "timefield", WindowType::TIMEFIELD }, - { "toolbox", WindowType::TOOLBOX }, - { "tristatebox", WindowType::TRISTATEBOX }, - { "warningbox", WindowType::WARNINGBOX }, - { "window", WindowType::WINDOW }, - { "workwindow", WindowType::WORKWINDOW }, - { "tabpagecontainer", WindowType::CONTROL }, - { "tabpagemodel", WindowType::TABPAGE } +static ComponentInfo const aComponentInfos [] = +{ + { OUStringLiteral("animatedimages"), WindowType::CONTROL }, + { OUStringLiteral("buttondialog"), WindowType::BUTTONDIALOG }, + { OUStringLiteral("cancelbutton"), WindowType::CANCELBUTTON }, + { OUStringLiteral("checkbox"), WindowType::CHECKBOX }, + { OUStringLiteral("combobox"), WindowType::COMBOBOX }, + { OUStringLiteral("control"), WindowType::CONTROL }, + { OUStringLiteral("currencybox"), WindowType::CURRENCYBOX }, + { OUStringLiteral("currencyfield"), WindowType::CURRENCYFIELD }, + { OUStringLiteral("datebox"), WindowType::DATEBOX }, + { OUStringLiteral("datefield"), WindowType::DATEFIELD }, + { OUStringLiteral("dialog"), WindowType::DIALOG }, + { OUStringLiteral("dockingarea"), WindowType::DOCKINGAREA }, + { OUStringLiteral("dockingwindow"), WindowType::DOCKINGWINDOW }, + { OUStringLiteral("edit"), WindowType::EDIT }, + { OUStringLiteral("errorbox"), WindowType::ERRORBOX }, + { OUStringLiteral("fixedbitmap"), WindowType::FIXEDBITMAP }, + { OUStringLiteral("fixedimage"), WindowType::FIXEDIMAGE }, + { OUStringLiteral("fixedline"), WindowType::FIXEDLINE }, + { OUStringLiteral("fixedtext"), WindowType::FIXEDTEXT }, + { OUStringLiteral("floatingwindow"), WindowType::FLOATINGWINDOW }, + { OUStringLiteral("frame"), WindowType::GROUPBOX }, + { OUStringLiteral("framewindow"), WindowType::TOOLKIT_FRAMEWINDOW }, + { OUStringLiteral("groupbox"), WindowType::GROUPBOX }, + { OUStringLiteral("helpbutton"), WindowType::HELPBUTTON }, + { OUStringLiteral("imagebutton"), WindowType::IMAGEBUTTON }, + { OUStringLiteral("infobox"), WindowType::INFOBOX }, + { OUStringLiteral("listbox"), WindowType::LISTBOX }, + { OUStringLiteral("longcurrencybox"), WindowType::LONGCURRENCYBOX }, + { OUStringLiteral("longcurrencyfield"), WindowType::LONGCURRENCYFIELD }, + { OUStringLiteral("menubutton"), WindowType::MENUBUTTON }, + { OUStringLiteral("messbox"), WindowType::MESSBOX }, + { OUStringLiteral("metricbox"), WindowType::METRICBOX }, + { OUStringLiteral("metricfield"), WindowType::METRICFIELD }, + { OUStringLiteral("modaldialog"), WindowType::MODALDIALOG }, + { OUStringLiteral("modelessdialog"), WindowType::MODELESSDIALOG }, + { OUStringLiteral("morebutton"), WindowType::MOREBUTTON }, + { OUStringLiteral("multilineedit"), WindowType::MULTILINEEDIT }, + { OUStringLiteral("multilistbox"), WindowType::MULTILISTBOX }, + { OUStringLiteral("numericbox"), WindowType::NUMERICBOX }, + { OUStringLiteral("numericfield"), WindowType::NUMERICFIELD }, + { OUStringLiteral("okbutton"), WindowType::OKBUTTON }, + { OUStringLiteral("patternbox"), WindowType::PATTERNBOX }, + { OUStringLiteral("patternfield"), WindowType::PATTERNFIELD }, + { OUStringLiteral("pushbutton"), WindowType::PUSHBUTTON }, + { OUStringLiteral("querybox"), WindowType::QUERYBOX }, + { OUStringLiteral("radiobutton"), WindowType::RADIOBUTTON }, + { OUStringLiteral("scrollbar"), WindowType::SCROLLBAR }, + { OUStringLiteral("scrollbarbox"), WindowType::SCROLLBARBOX }, + { OUStringLiteral("spinbutton"), WindowType::SPINBUTTON }, + { OUStringLiteral("spinfield"), WindowType::SPINFIELD }, + { OUStringLiteral("splitter"), WindowType::SPLITTER }, + { OUStringLiteral("splitwindow"), WindowType::SPLITWINDOW }, + { OUStringLiteral("statusbar"), WindowType::STATUSBAR }, + { OUStringLiteral("systemchildwindow"), WindowType::TOOLKIT_SYSTEMCHILDWINDOW }, + { OUStringLiteral("tabcontrol"), WindowType::TABCONTROL }, + { OUStringLiteral("tabdialog"), WindowType::TABDIALOG }, + { OUStringLiteral("tabpage"), WindowType::TABPAGE }, + { OUStringLiteral("tabpagecontainer"), WindowType::CONTROL }, + { OUStringLiteral("tabpagemodel"), WindowType::TABPAGE }, + { OUStringLiteral("timebox"), WindowType::TIMEBOX }, + { OUStringLiteral("timefield"), WindowType::TIMEFIELD }, + { OUStringLiteral("toolbox"), WindowType::TOOLBOX }, + { OUStringLiteral("tristatebox"), WindowType::TRISTATEBOX }, + { OUStringLiteral("warningbox"), WindowType::WARNINGBOX }, + { OUStringLiteral("window"), WindowType::WINDOW }, + { OUStringLiteral("workwindow"), WindowType::WORKWINDOW } }; -extern "C" -{ -static int ComponentInfoCompare( const void* pFirst, const void* pSecond) +bool ComponentInfoCompare( const ComponentInfo & lhs, const ComponentInfo & rhs) { - return strcmp( static_cast<ComponentInfo const *>(pFirst)->pName, - static_cast<ComponentInfo const *>(pSecond)->pName ); + return rtl_str_compare_WithLength(lhs.sName.data, lhs.sName.size, rhs.sName.data, rhs.sName.size) < 0; } + +bool ComponentInfoFindCompare( const ComponentInfo & lhs, const OUString & s) +{ + return rtl_ustr_ascii_compareIgnoreAsciiCase_WithLengths(s.pData->buffer, s.pData->length, + lhs.sName.data, lhs.sName.size) > 0; } WindowType ImplGetComponentType( const OUString& rServiceName ) @@ -775,28 +777,22 @@ WindowType ImplGetComponentType( const OUString& rServiceName ) static bool bSorted = false; if( !bSorted ) { - qsort( static_cast<void*>(aComponentInfos), - SAL_N_ELEMENTS( aComponentInfos ), - sizeof( ComponentInfo ), - ComponentInfoCompare ); + assert( std::is_sorted( std::begin(aComponentInfos), std::end(aComponentInfos), + ComponentInfoCompare ) ); bSorted = true; } - - ComponentInfo aSearch; - OString aServiceName(OUStringToOString(rServiceName, osl_getThreadTextEncoding()).toAsciiLowerCase()); - if ( !aServiceName.isEmpty() ) - aSearch.pName = aServiceName.getStr(); + OUString sSearch; + if ( !rServiceName.isEmpty() ) + sSearch = rServiceName; else - aSearch.pName = "window"; - - ComponentInfo* pInf = static_cast<ComponentInfo*>(bsearch( &aSearch, - static_cast<void*>(aComponentInfos), - SAL_N_ELEMENTS( aComponentInfos ), - sizeof( ComponentInfo ), - ComponentInfoCompare )); + sSearch = "window"; - return pInf ? pInf->nWinType : WindowType::NONE; + auto it = std::lower_bound( std::begin(aComponentInfos), std::end(aComponentInfos), sSearch, + ComponentInfoFindCompare ); + if (it != std::end(aComponentInfos) && !ComponentInfoFindCompare(*it, sSearch) ) + return it->nWinType; + return WindowType::NONE; } struct MessageBoxTypeInfo diff --git a/toolkit/source/helper/vclunohelper.cxx b/toolkit/source/helper/vclunohelper.cxx index d7dfe76e162e..6e466468e2f1 100644 --- a/toolkit/source/helper/vclunohelper.cxx +++ b/toolkit/source/helper/vclunohelper.cxx @@ -360,10 +360,10 @@ namespace { static struct _unit_table { - FieldUnit const eFieldUnit; - sal_Int16 const nMeasurementUnit; - sal_Int16 const nFieldToMeasureFactor; - } aUnits[] = { + FieldUnit eFieldUnit; + sal_Int16 nMeasurementUnit; + sal_Int16 nFieldToMeasureFactor; + } const aUnits[] = { { FUNIT_NONE, -1 , -1}, { FUNIT_MM, MeasureUnit::MM, 1 }, // must precede MM_10TH { FUNIT_MM, MeasureUnit::MM_10TH, 10 }, |