types: use regular array for map entries

This array is only initialized once.

Signed-off-by: Ran Benita <ran234@gmail.com>
master
Ran Benita 2012-08-07 08:52:23 +03:00
parent 8ccfee82ec
commit b2fba7305c
6 changed files with 29 additions and 19 deletions

View File

@ -344,7 +344,7 @@ write_keycodes(struct xkb_keymap *keymap, struct buf *buf)
static bool static bool
write_types(struct xkb_keymap *keymap, struct buf *buf) write_types(struct xkb_keymap *keymap, struct buf *buf)
{ {
unsigned int i; unsigned int i, j;
xkb_level_index_t n; xkb_level_index_t n;
struct xkb_key_type *type; struct xkb_key_type *type;
struct xkb_kt_map_entry *entry; 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, get_mod_mask_text(keymap, type->mods.real_mods,
type->mods.vmods)); type->mods.vmods));
darray_foreach(entry, type->map) { for (j = 0; j < type->num_entries; j++) {
char *str; char *str;
entry = &type->map[j];
/* /*
* Printing level 1 entries is redundant, it's the default, * Printing level 1 entries is redundant, it's the default,

View File

@ -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_keymap *keymap = xkb_state_get_map(state);
struct xkb_key_type *type; struct xkb_key_type *type;
struct xkb_kt_map_entry *entry; unsigned int i;
xkb_mod_mask_t active_mods; xkb_mod_mask_t active_mods;
if (!XkbKeycodeInRange(keymap, kc)) 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 = xkb_state_serialize_mods(state, XKB_STATE_EFFECTIVE);
active_mods &= type->mods.mask; active_mods &= type->mods.mask;
darray_foreach(entry, type->map) { for (i = 0; i < type->num_entries; i++)
if (entry->mods.mask == active_mods) if (type->map[i].mods.mask == active_mods)
return entry->level; return type->map[i].level;
}
return 0; return 0;
} }

View File

@ -250,7 +250,8 @@ struct xkb_kt_map_entry {
struct xkb_key_type { struct xkb_key_type {
struct xkb_mods mods; struct xkb_mods mods;
xkb_level_index_t num_levels; 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 *name;
const char **level_names; const char **level_names;
}; };

View File

@ -1473,10 +1473,9 @@ UpdateModifiersFromCompat(struct xkb_keymap *keymap)
xkb_mod_index_t vmod; xkb_mod_index_t vmod;
xkb_group_index_t grp; xkb_group_index_t grp;
xkb_led_index_t led; xkb_led_index_t led;
unsigned int i; unsigned int i, j;
struct xkb_key *key; struct xkb_key *key;
struct xkb_key_type *type; struct xkb_key_type *type;
struct xkb_kt_map_entry *entry;
/* Find all the interprets for the key and bind them to actions, /* Find all the interprets for the key and bind them to actions,
* which will also update the vmodmap. */ * which will also update the vmodmap. */
@ -1513,9 +1512,12 @@ UpdateModifiersFromCompat(struct xkb_keymap *keymap)
mask |= keymap->vmods[vmod]; mask |= keymap->vmods[vmod];
} }
darray_foreach(entry, type->map) for (j = 0; j < type->num_entries; j++) {
entry->mods.mask = entry->mods.real_mods | type->map[j].mods.mask = 0;
VModsToReal(keymap, entry->mods.vmods); 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. */ /* Update action modifiers. */

View File

@ -989,25 +989,31 @@ HandleKeyTypesFile(KeyTypesInfo *info, XkbFile *file, enum merge_mode merge)
static bool static bool
ComputeEffectiveMap(struct xkb_keymap *keymap, struct xkb_key_type *type) 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; struct xkb_kt_map_entry *entry = NULL;
if (type->mods.vmods != 0) { if (type->mods.vmods != 0) {
tmp = VModsToReal(keymap, type->mods.vmods); tmp = VModsToReal(keymap, type->mods.vmods);
type->mods.mask = tmp | type->mods.real_mods; 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; tmp = 0;
if (entry->mods.vmods != 0) { if (entry->mods.vmods != 0) {
tmp = VModsToReal(keymap, entry->mods.vmods); tmp = VModsToReal(keymap, entry->mods.vmods);
if (tmp == 0) if (tmp == 0)
continue; continue;
} }
entry->mods.mask = entry->mods.mask =
(entry->mods.real_mods | tmp) & type->mods.mask; (entry->mods.real_mods | tmp) & type->mods.mask;
} }
} }
else else {
type->mods.mask = type->mods.real_mods; type->mods.mask = type->mods.real_mods;
}
return true; return true;
} }
@ -1044,7 +1050,9 @@ CopyDefToKeyType(KeyTypesInfo *info, KeyTypeInfo *def,
type->mods.real_mods = def->mask; type->mods.real_mods = def->mask;
type->mods.vmods = def->vmask; type->mods.vmods = def->vmask;
type->num_levels = def->num_levels; 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->name = xkb_atom_text(keymap->ctx, def->name);
@ -1069,7 +1077,6 @@ CopyDefToKeyType(KeyTypesInfo *info, KeyTypeInfo *def,
type->level_names = NULL; type->level_names = NULL;
} }
darray_init(def->entries);
return ComputeEffectiveMap(keymap, type); return ComputeEffectiveMap(keymap, type);
} }

View File

@ -354,7 +354,7 @@ xkb_map_unref(struct xkb_keymap *keymap)
return; return;
for (i = 0; i < keymap->num_types; i++) { 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[i].level_names);
} }
free(keymap->types); free(keymap->types);