types: use regular array for map entries This array is only initialized once. 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 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168
diff --git a/src/keymap-dump.c b/src/keymap-dump.c
index deeea36..b2a08b6 100644
--- a/src/keymap-dump.c
+++ b/src/keymap-dump.c
@@ -344,7 +344,7 @@ write_keycodes(struct xkb_keymap *keymap, struct buf *buf)
static bool
write_types(struct xkb_keymap *keymap, struct buf *buf)
{
- unsigned int i;
+ unsigned int i, j;
xkb_level_index_t n;
struct xkb_key_type *type;
struct xkb_kt_map_entry *entry;
@@ -366,8 +366,9 @@ write_types(struct xkb_keymap *keymap, struct buf *buf)
get_mod_mask_text(keymap, type->mods.real_mods,
type->mods.vmods));
- darray_foreach(entry, type->map) {
+ for (j = 0; j < type->num_entries; j++) {
char *str;
+ entry = &type->map[j];
/*
* Printing level 1 entries is redundant, it's the default,
diff --git a/src/map.c b/src/map.c
index d602c90..b0d077f 100644
--- a/src/map.c
+++ b/src/map.c
@@ -219,7 +219,7 @@ xkb_key_get_level(struct xkb_state *state, xkb_keycode_t kc,
{
struct xkb_keymap *keymap = xkb_state_get_map(state);
struct xkb_key_type *type;
- struct xkb_kt_map_entry *entry;
+ unsigned int i;
xkb_mod_mask_t active_mods;
if (!XkbKeycodeInRange(keymap, kc))
@@ -229,10 +229,9 @@ xkb_key_get_level(struct xkb_state *state, xkb_keycode_t kc,
active_mods = xkb_state_serialize_mods(state, XKB_STATE_EFFECTIVE);
active_mods &= type->mods.mask;
- darray_foreach(entry, type->map) {
- if (entry->mods.mask == active_mods)
- return entry->level;
- }
+ for (i = 0; i < type->num_entries; i++)
+ if (type->map[i].mods.mask == active_mods)
+ return type->map[i].level;
return 0;
}
diff --git a/src/xkb-priv.h b/src/xkb-priv.h
index 1b630c8..95b243e 100644
--- a/src/xkb-priv.h
+++ b/src/xkb-priv.h
@@ -250,7 +250,8 @@ struct xkb_kt_map_entry {
struct xkb_key_type {
struct xkb_mods mods;
xkb_level_index_t num_levels;
- darray(struct xkb_kt_map_entry) map;
+ struct xkb_kt_map_entry *map;
+ unsigned int num_entries;
const char *name;
const char **level_names;
};
diff --git a/src/xkbcomp/compat.c b/src/xkbcomp/compat.c
index 33315ad..9007180 100644
--- a/src/xkbcomp/compat.c
+++ b/src/xkbcomp/compat.c
@@ -1473,10 +1473,9 @@ UpdateModifiersFromCompat(struct xkb_keymap *keymap)
xkb_mod_index_t vmod;
xkb_group_index_t grp;
xkb_led_index_t led;
- unsigned int i;
+ unsigned int i, j;
struct xkb_key *key;
struct xkb_key_type *type;
- struct xkb_kt_map_entry *entry;
/* Find all the interprets for the key and bind them to actions,
* which will also update the vmodmap. */
@@ -1513,9 +1512,12 @@ UpdateModifiersFromCompat(struct xkb_keymap *keymap)
mask |= keymap->vmods[vmod];
}
- darray_foreach(entry, type->map)
- entry->mods.mask = entry->mods.real_mods |
- VModsToReal(keymap, entry->mods.vmods);
+ for (j = 0; j < type->num_entries; j++) {
+ type->map[j].mods.mask = 0;
+ type->map[j].mods.mask |= type->map[j].mods.real_mods;
+ type->map[j].mods.mask |= VModsToReal(keymap,
+ type->map[j].mods.vmods);
+ }
}
/* Update action modifiers. */
diff --git a/src/xkbcomp/keytypes.c b/src/xkbcomp/keytypes.c
index 560d295..3f6a290 100644
--- a/src/xkbcomp/keytypes.c
+++ b/src/xkbcomp/keytypes.c
@@ -989,25 +989,31 @@ HandleKeyTypesFile(KeyTypesInfo *info, XkbFile *file, enum merge_mode merge)
static bool
ComputeEffectiveMap(struct xkb_keymap *keymap, struct xkb_key_type *type)
{
- uint32_t tmp;
+ unsigned int i;
+ xkb_mod_mask_t tmp;
struct xkb_kt_map_entry *entry = NULL;
if (type->mods.vmods != 0) {
tmp = VModsToReal(keymap, type->mods.vmods);
type->mods.mask = tmp | type->mods.real_mods;
- darray_foreach(entry, type->map) {
+
+ for (i = 0; i < type->num_entries; i++) {
+ entry = &type->map[i];
tmp = 0;
+
if (entry->mods.vmods != 0) {
tmp = VModsToReal(keymap, entry->mods.vmods);
if (tmp == 0)
continue;
}
+
entry->mods.mask =
(entry->mods.real_mods | tmp) & type->mods.mask;
}
}
- else
+ else {
type->mods.mask = type->mods.real_mods;
+ }
return true;
}
@@ -1044,7 +1050,9 @@ CopyDefToKeyType(KeyTypesInfo *info, KeyTypeInfo *def,
type->mods.real_mods = def->mask;
type->mods.vmods = def->vmask;
type->num_levels = def->num_levels;
- memcpy(&type->map, &def->entries, sizeof(def->entries));
+ type->map = darray_mem(def->entries, 0);
+ type->num_entries = darray_size(def->entries);
+ darray_init(def->entries);
type->name = xkb_atom_text(keymap->ctx, def->name);
@@ -1069,7 +1077,6 @@ CopyDefToKeyType(KeyTypesInfo *info, KeyTypeInfo *def,
type->level_names = NULL;
}
- darray_init(def->entries);
return ComputeEffectiveMap(keymap, type);
}
diff --git a/src/xkbcomp/xkbcomp.c b/src/xkbcomp/xkbcomp.c
index b79166b..2932ba3 100644
--- a/src/xkbcomp/xkbcomp.c
+++ b/src/xkbcomp/xkbcomp.c
@@ -354,7 +354,7 @@ xkb_map_unref(struct xkb_keymap *keymap)
return;
for (i = 0; i < keymap->num_types; i++) {
- darray_free(keymap->types[i].map);
+ free(keymap->types[i].map);
free(keymap->types[i].level_names);
}
free(keymap->types);