summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRan Benita <ran234@gmail.com>2013-03-04 10:33:18 +0200
committerDaniel Stone <daniel@fooishbar.org>2013-03-18 22:20:05 +0000
commitea3cf26db5c6b71a7e3cb755c03db6757fd6634f (patch)
tree2561dddba5a9ea0a0f4ca9883590eb980957094a /src
parentcd6a71fc63577004ebc8a0e43a6cac260b8ff60d (diff)
keycodes: don't do unnecessary copies while merging
If 'into' in empty we can just steal 'from'. Also move the alias-merging into the big function, it's nicer this way. Signed-off-by: Ran Benita <ran234@gmail.com>
Diffstat (limited to 'src')
-rw-r--r--src/xkbcomp/keycodes.c101
1 files changed, 52 insertions, 49 deletions
diff --git a/src/xkbcomp/keycodes.c b/src/xkbcomp/keycodes.c
index e25d141..53e3fff 100644
--- a/src/xkbcomp/keycodes.c
+++ b/src/xkbcomp/keycodes.c
@@ -343,43 +343,10 @@ AddKeyName(KeyNamesInfo *info, xkb_keycode_t kc, xkb_atom_t name,
static int
HandleAliasDef(KeyNamesInfo *info, KeyAliasDef *def, enum merge_mode merge);
-static bool
-MergeAliases(KeyNamesInfo *into, KeyNamesInfo *from, enum merge_mode merge)
-{
- AliasInfo *alias;
- KeyAliasDef def;
-
- if (darray_empty(from->aliases))
- return true;
-
- if (darray_empty(into->aliases)) {
- into->aliases = from->aliases;
- darray_init(from->aliases);
- return true;
- }
-
- memset(&def, 0, sizeof(def));
-
- darray_foreach(alias, from->aliases) {
- def.merge = (merge == MERGE_DEFAULT) ? alias->merge : merge;
- def.alias = alias->alias;
- def.real = alias->real;
-
- if (!HandleAliasDef(into, &def, def.merge))
- return false;
- }
-
- return true;
-}
-
static void
MergeIncludedKeycodes(KeyNamesInfo *into, KeyNamesInfo *from,
enum merge_mode merge)
{
- xkb_keycode_t i;
- xkb_led_index_t idx;
- LedNameInfo *ledi;
-
if (from->errorCount > 0) {
into->errorCount += from->errorCount;
return;
@@ -390,29 +357,65 @@ MergeIncludedKeycodes(KeyNamesInfo *into, KeyNamesInfo *from,
from->name = NULL;
}
- if (darray_size(into->key_names) < darray_size(from->key_names))
- darray_resize0(into->key_names, darray_size(from->key_names));
+ /* Merge key names. */
+ if (darray_empty(into->key_names)) {
+ into->key_names = from->key_names;
+ darray_init(from->key_names);
+ into->min_key_code = from->min_key_code;
+ into->max_key_code = from->max_key_code;
+ }
+ else {
+ if (darray_size(into->key_names) < darray_size(from->key_names))
+ darray_resize0(into->key_names, darray_size(from->key_names));
- for (i = from->min_key_code; i <= from->max_key_code; i++) {
- xkb_atom_t name = darray_item(from->key_names, i).name;
- if (name == XKB_ATOM_NONE)
- continue;
+ for (unsigned i = from->min_key_code; i <= from->max_key_code; i++) {
+ xkb_atom_t name = darray_item(from->key_names, i).name;
+ if (name == XKB_ATOM_NONE)
+ continue;
- if (!AddKeyName(into, i, name, merge, from->file_id, false))
- into->errorCount++;
+ if (!AddKeyName(into, i, name, merge, from->file_id, false))
+ into->errorCount++;
+ }
}
- darray_enumerate(idx, ledi, from->led_names) {
- if (ledi->name == XKB_ATOM_NONE)
- continue;
+ /* Merge key aliases. */
+ if (darray_empty(into->aliases)) {
+ into->aliases = from->aliases;
+ darray_init(from->aliases);
+ }
+ else {
+ AliasInfo *alias;
+
+ darray_foreach(alias, from->aliases) {
+ KeyAliasDef def;
+
+ def.merge = (merge == MERGE_DEFAULT ? alias->merge : merge);
+ def.alias = alias->alias;
+ def.real = alias->real;
+
+ if (!HandleAliasDef(into, &def, def.merge))
+ into->errorCount++;
+ }
+ }
- ledi->merge = (merge == MERGE_DEFAULT ? ledi->merge : merge);
- if (!AddLedName(into, ledi->merge, ledi, idx))
- into->errorCount++;
+ /* Merge LED names. */
+ if (darray_empty(into->led_names)) {
+ into->led_names = from->led_names;
+ darray_init(from->led_names);
}
+ else {
+ xkb_led_index_t idx;
+ LedNameInfo *ledi;
+
+ darray_enumerate(idx, ledi, from->led_names) {
+ if (ledi->name == XKB_ATOM_NONE)
+ continue;
- if (!MergeAliases(into, from, merge))
- into->errorCount++;
+ ledi->merge = (merge == MERGE_DEFAULT ? ledi->merge : merge);
+ if (!AddLedName(into, ledi->merge, ledi, idx))
+ into->errorCount++;
+ }
+ }
}
static void