compose: remove the keysym_from_name cache The hit rate is high, but either the cache is slow or the function is not fast enough -- the cache no longer holds its weight, leading only to very modest improvements. If it's the former, it can definitely be improved, the code is very dumb (though it worked just as well as any other I tried back then). But instead, let's just kill it. Signed-off-by: Ran Benita <ran234@gmail.com>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
diff --git a/src/compose/parser.c b/src/compose/parser.c
index 763d29e..fd2dca9 100644
--- a/src/compose/parser.c
+++ b/src/compose/parser.c
@@ -64,45 +64,6 @@ OR PERFORMANCE OF THIS SOFTWARE.
#define MAX_LHS_LEN 10
#define MAX_INCLUDE_DEPTH 5
-#define KEYSYM_FROM_NAME_CACHE_SIZE 8
-
-/*
- * xkb_keysym_from_name() is fairly slow, because for internal reasons
- * it must use strcasecmp().
- * A small cache reduces about 20% from the compilation time of
- * en_US.UTF-8/Compose.
- */
-struct keysym_from_name_cache {
- struct {
- char name[64];
- unsigned len;
- xkb_keysym_t keysym;
- } cache[KEYSYM_FROM_NAME_CACHE_SIZE];
- unsigned next;
-};
-
-static xkb_keysym_t
-cached_keysym_from_name(struct keysym_from_name_cache *cache,
- const char *name, size_t len)
-{
- xkb_keysym_t keysym;
-
- if (len >= sizeof(cache->cache[0].name))
- return XKB_KEY_NoSymbol;
-
- for (unsigned i = 0; i < KEYSYM_FROM_NAME_CACHE_SIZE; i++)
- if (cache->cache[i].len == len &&
- memcmp(cache->cache[i].name, name, len) == 0)
- return cache->cache[i].keysym;
-
- keysym = xkb_keysym_from_name(name, XKB_KEYSYM_NO_FLAGS);
- strcpy(cache->cache[cache->next].name, name);
- cache->cache[cache->next].len = len;
- cache->cache[cache->next].keysym = keysym;
- cache->next = (cache->next + 1) % KEYSYM_FROM_NAME_CACHE_SIZE;
- return keysym;
-}
-
/*
* Grammar adapted from libX11/modules/im/ximcp/imLcPrs.c.
* See also the XCompose(5) manpage.
@@ -536,7 +497,6 @@ parse(struct xkb_compose_table *table, struct scanner *s,
{
enum rules_token tok;
union lvalue val;
- struct keysym_from_name_cache *cache = s->priv;
xkb_keysym_t keysym;
struct production production;
enum { MAX_ERRORS = 10 };
@@ -612,7 +572,7 @@ lhs_keysym:
lhs_keysym_tok:
switch (tok) {
case TOK_LHS_KEYSYM:
- keysym = cached_keysym_from_name(cache, val.string.str, val.string.len);
+ keysym = xkb_keysym_from_name(val.string.str, XKB_KEYSYM_NO_FLAGS);
if (keysym == XKB_KEY_NoSymbol) {
scanner_err(s, "unrecognized keysym \"%s\" on left-hand side",
val.string.str);
@@ -683,7 +643,7 @@ rhs:
production.has_string = true;
goto rhs;
case TOK_IDENT:
- keysym = cached_keysym_from_name(cache, val.string.str, val.string.len);
+ keysym = xkb_keysym_from_name(val.string.str, XKB_KEYSYM_NO_FLAGS);
if (keysym == XKB_KEY_NoSymbol) {
scanner_err(s, "unrecognized keysym \"%s\" on right-hand side",
val.string.str);
@@ -735,9 +695,7 @@ parse_string(struct xkb_compose_table *table, const char *string, size_t len,
const char *file_name)
{
struct scanner s;
- struct keysym_from_name_cache cache;
- memset(&cache, 0, sizeof(cache));
- scanner_init(&s, table->ctx, string, len, file_name, &cache);
+ scanner_init(&s, table->ctx, string, len, file_name, NULL);
if (!parse(table, &s, 0))
return false;
/* Maybe the allocator can use the excess space. */