summaryrefslogtreecommitdiff
path: root/include/basic
diff options
context:
space:
mode:
authorMike Kaganski <mike.kaganski@collabora.com>2020-12-22 21:42:49 +0300
committerMike Kaganski <mike.kaganski@collabora.com>2020-12-23 15:42:46 +0100
commitf7de7de1189ae4e63f73468076da47b37fe61ede (patch)
tree45838b81429257c3777a1352dca9d36a8849e213 /include/basic
parent49891758278fff055e9ef631078bf08cbf8ba7d6 (diff)
Initialize method mapping table at compile time
This removes the need to calculate hashes for the table at runtime. Also this introduces a static assertion to make sure that the table has correct structure, and fixes some methods that had wrong argument counts: CreateUnoListener: 1 -> 2 MIRR: 2 -> 3 SLN: 2 -> 3 SYD: 2 -> 4 Changes in basic/source/classes/sb.cxx are related to the change of SbxVariable::MakeHashCode into constexpr function taking string view. Change-Id: I2fec4994e976f36c4b647c30b51a9e879a815775 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/108220 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'include/basic')
-rw-r--r--include/basic/sbxvar.hxx17
1 files changed, 16 insertions, 1 deletions
diff --git a/include/basic/sbxvar.hxx b/include/basic/sbxvar.hxx
index 14c3eb97a788..487b910aac84 100644
--- a/include/basic/sbxvar.hxx
+++ b/include/basic/sbxvar.hxx
@@ -20,10 +20,12 @@
#ifndef INCLUDED_BASIC_SBXVAR_HXX
#define INCLUDED_BASIC_SBXVAR_HXX
+#include <rtl/character.hxx>
#include <rtl/ustring.hxx>
#include <basic/sbxcore.hxx>
#include <basic/basicdllapi.h>
+#include <algorithm>
#include <cstddef>
#include <cstring>
#include <memory>
@@ -299,7 +301,20 @@ public:
StarBASIC* pParentBasic );
void ClearComListener();
- static sal_uInt16 MakeHashCode( const OUString& rName );
+ // Create a simple hashcode: the first six characters are evaluated.
+ static constexpr sal_uInt16 MakeHashCode(std::u16string_view aName)
+ {
+ sal_uInt16 n = 0;
+ const auto first6 = aName.substr(0, 6);
+ for (const auto& c : first6)
+ {
+ // If we have a comment sign break!!
+ if (c >= 0x80)
+ return 0;
+ n = static_cast<sal_uInt16>((n << 3) + rtl::toAsciiUpperCase(c));
+ }
+ return n;
+ }
};
typedef tools::SvRef<SbxObject> SbxObjectRef;