summaryrefslogtreecommitdiff
path: root/src/keymap.c
diff options
context:
space:
mode:
authorRan Benita <ran234@gmail.com>2012-08-12 11:40:02 +0300
committerDaniel Stone <daniel@fooishbar.org>2013-04-01 18:20:57 +0100
commita392d2682bfbf5ce6c3ee153c6a08bb456da0660 (patch)
tree154727f033a8653a2cfa0a7fd861e15e742baa45 /src/keymap.c
parente4bceec8809f2563af6786678442fa70d4cd728c (diff)
downloadxorg-lib-libxkbcommon-a392d2682bfbf5ce6c3ee153c6a08bb456da0660.tar.gz
Replace flex scanner with a hand-written one
The scanner is very similar in structure to the one in xkbcomp/rules.c. It avoids copying and has nicer error reporting. It uses gperf to generate a hashtable for the keywords, which gives a nice speed boost (compared to the naive strcasecmp method at least). But since there's hardly a reason to regenerate it every time and require people to install gperf, the output (keywords.c) is added here as well. Here are some stats from test/rulescomp: Before: compiled 1000 keymaps in 4.052939625s ==22063== total heap usage: 101,101 allocs, 101,101 frees, 11,840,834 bytes allocated After: compiled 1000 keymaps in 3.519665434s ==26505== total heap usage: 99,945 allocs, 99,945 frees, 7,033,608 bytes allocated Signed-off-by: Ran Benita <ran234@gmail.com>
Diffstat (limited to 'src/keymap.c')
-rw-r--r--src/keymap.c32
1 files changed, 2 insertions, 30 deletions
diff --git a/src/keymap.c b/src/keymap.c
index 3df183a..55000f4 100644
--- a/src/keymap.c
+++ b/src/keymap.c
@@ -190,35 +190,7 @@ xkb_keymap_new_from_string(struct xkb_context *ctx,
enum xkb_keymap_format format,
enum xkb_keymap_compile_flags flags)
{
- struct xkb_keymap *keymap;
- const struct xkb_keymap_format_ops *ops;
-
- ops = get_keymap_format_ops(format);
- if (!ops || !ops->keymap_new_from_string) {
- log_err_func(ctx, "unsupported keymap format: %d\n", format);
- return NULL;
- }
-
- if (flags & ~(XKB_MAP_COMPILE_PLACEHOLDER)) {
- log_err_func(ctx, "unrecognized flags: %#x\n", flags);
- return NULL;
- }
-
- if (!string) {
- log_err_func1(ctx, "no string specified\n");
- return NULL;
- }
-
- keymap = xkb_keymap_new(ctx, format, flags);
- if (!keymap)
- return NULL;
-
- if (!ops->keymap_new_from_string(keymap, string)) {
- xkb_keymap_unref(keymap);
- return NULL;
- }
-
- return keymap;
+ return xkb_keymap_new_from_buffer(ctx, string, SIZE_MAX, format, flags);
}
XKB_EXPORT struct xkb_keymap *
@@ -250,7 +222,7 @@ xkb_keymap_new_from_buffer(struct xkb_context *ctx,
if (!keymap)
return NULL;
- if (!ops->keymap_new_from_buffer(keymap, buffer, length)) {
+ if (!ops->keymap_new_from_string(keymap, buffer, length)) {
xkb_keymap_unref(keymap);
return NULL;
}