summaryrefslogtreecommitdiff
path: root/include/basic
diff options
context:
space:
mode:
authorMike Kaganski <mike.kaganski@collabora.com>2022-04-04 09:58:53 +0300
committerMike Kaganski <mike.kaganski@collabora.com>2022-04-04 11:06:00 +0200
commitde81c2545aec06a1b269218b7d00656e97d8b66c (patch)
tree8547e57d8ef9a3141687fd177700d36dc4be21b2 /include/basic
parentaf38d84380ee78f61822e8e080a56e955842b71e (diff)
Related: tdf#144245 Optimize case-insensitive handling
1. Make BasicCollection::implGetIndexForName take OUString again, after commit f7de7de1189ae4e63f73468076da47b37fe61ede made it take std::u16string_view. All call sites pass OUStrings, and commit ef32c3b4f9b80918d6018e14297fa41245afd381 made it create OUString from the argument. 2. Have SbxVariable cache a case-insensitive variant of the name. It is currently only used in the Collection implementation, but may be used in other places; Tthe names are case-insensitive in Basic, and VBA allows non-ASCII characters in names, so this caching might be useful elsewhere. 3. Skip non-ASCII characters when calculating name hash, to allow non-ASCII-containing strings still have some hash variance, when at least some of the first 6 characters are ASCII. Change-Id: If90ccea2c4b44c34967e6b764b6fab45b2976c40 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/132493 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'include/basic')
-rw-r--r--include/basic/sbxdef.hxx1
-rw-r--r--include/basic/sbxvar.hxx6
2 files changed, 4 insertions, 3 deletions
diff --git a/include/basic/sbxdef.hxx b/include/basic/sbxdef.hxx
index b52b0beb3c7d..e85f1a209664 100644
--- a/include/basic/sbxdef.hxx
+++ b/include/basic/sbxdef.hxx
@@ -122,6 +122,7 @@ enum SbxOperator {
enum class SbxNameType { // Type of the questioned name of a variable
NONE, // plain name
+ CaseInsensitive, // plain name - case insensitive
ShortTypes, // Name%(A%,B$)
};
diff --git a/include/basic/sbxvar.hxx b/include/basic/sbxvar.hxx
index 1f1ac8a8c4fc..d302f26637bd 100644
--- a/include/basic/sbxvar.hxx
+++ b/include/basic/sbxvar.hxx
@@ -248,6 +248,7 @@ class BASIC_DLLPUBLIC SbxVariable : public SbxValue
StarBASIC* m_pComListenerParentBasic = nullptr;
std::unique_ptr<SfxBroadcaster> mpBroadcaster; // Broadcaster, if needed
OUString maName; // Name, if available
+ mutable OUString maNameCI; // Name, case insentitive - cached for fast comparison
SbxArrayRef mpPar; // Parameter-Array, if set
sal_uInt16 nHash = 0; // Hash-ID for search
@@ -308,9 +309,8 @@ public:
const auto first6 = aName.substr(0, 6);
for (const auto& c : first6)
{
- // If we have a filthy non-ASCII character, break!!
- if (c >= 0x80)
- return 0;
+ if (!rtl::isAscii(c))
+ continue; // Just skip it to let non-ASCII strings have some hash variance
n = static_cast<sal_uInt16>((n << 3) + rtl::toAsciiUpperCase(c));
}
return n;