This array is only initialized once.
Signed-off-by: Ran Benita <ran234@gmail.com>
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;
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,
{
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))
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;
}
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;
};
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. */
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. */
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;
}
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);
type->level_names = NULL;
}
- darray_init(def->entries);
return ComputeEffectiveMap(keymap, type);
}
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);