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>
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 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
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