summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorRan Benita <ran@unusedvar.com>2021-04-01 22:46:56 +0300
committerRan Benita <ran@unusedvar.com>2021-04-01 22:52:59 +0300
commit45b1ca22052b79c83bd96b7c5828add156768b8e (patch)
treed24d9e793fd8d0c4cf40c07858b1e9ff75ff5f2c /scripts
parent8cd688c06378ebdb2def6f310fb1e78898b75bde (diff)
downloadxorg-lib-libxkbcommon-45b1ca22052b79c83bd96b7c5828add156768b8e.tar.gz
keysym: speed up the perfect hash function
Make it use a bit operation instead of an expensive modulo. perf diff: Baseline Delta Abs Shared Object Symbol ........ ......... ................. ................................... 28.15% -6.57% bench-compose [.] xkb_keysym_from_name Signed-off-by: Ran Benita <ran@unusedvar.com>
Diffstat (limited to 'scripts')
-rw-r--r--scripts/perfect_hash.py4
1 files changed, 3 insertions, 1 deletions
diff --git a/scripts/perfect_hash.py b/scripts/perfect_hash.py
index 0d7df42..b94ed98 100644
--- a/scripts/perfect_hash.py
+++ b/scripts/perfect_hash.py
@@ -195,7 +195,9 @@ class StrSaltHash(object):
self.salt = ''
def __call__(self, key):
- while len(self.salt) < len(key): # add more salt as necessary
+ # XXX: xkbcommon modification: make the salt length a power of 2
+ # so that the % operation in the hash is fast.
+ while len(self.salt) < max(len(key), 32): # add more salt as necessary
self.salt += random.choice(self.chars)
return sum(ord(self.salt[i]) * ord(c)