types: move preserve directly into xkb_kt_map_entry

Currently each xkb_key_type has a preserve array, which is only allocated
if a preserve[] statement is specified in the type. In this case each map
entry has an element in the array.

The space savings are negligible; put this field where it logically
belongs.

Signed-off-by: Ran Benita <ran234@gmail.com>
master
Ran Benita 2012-08-06 21:31:17 +03:00
parent 6b75dd2dcb
commit 233d85c427
4 changed files with 10 additions and 33 deletions

View File

@ -346,6 +346,7 @@ write_types(struct xkb_keymap *keymap, struct buf *buf)
{
int n;
struct xkb_key_type *type;
struct xkb_kt_map_entry *entry;
if (keymap->types_section_name)
write_buf(buf, "\txkb_types \"%s\" {\n\n",
@ -362,8 +363,7 @@ write_types(struct xkb_keymap *keymap, struct buf *buf)
get_mod_mask_text(keymap, type->mods.real_mods,
type->mods.vmods));
for (n = 0; n < darray_size(type->map); n++) {
struct xkb_kt_map_entry *entry = &darray_item(type->map, n);
darray_foreach(entry, type->map) {
char *str;
str = get_mod_mask_text(keymap, entry->mods.real_mods,
@ -371,13 +371,13 @@ write_types(struct xkb_keymap *keymap, struct buf *buf)
write_buf(buf, "\t\t\tmap[%s]= Level%d;\n",
str, entry->level + 1);
if (!type->preserve || (!type->preserve[n].real_mods &&
!type->preserve[n].vmods))
if (!entry->preserve.real_mods && !entry->preserve.vmods)
continue;
write_buf(buf, "\t\t\tpreserve[%s]= ", str);
write_buf(buf, "%s;\n",
get_mod_mask_text(keymap, type->preserve[n].real_mods,
type->preserve[n].vmods));
get_mod_mask_text(keymap, entry->preserve.real_mods,
entry->preserve.vmods));
}
if (type->level_names) {

View File

@ -244,13 +244,13 @@ struct xkb_mods {
struct xkb_kt_map_entry {
xkb_level_index_t level;
struct xkb_mods mods;
struct xkb_mods preserve;
};
struct xkb_key_type {
struct xkb_mods mods;
xkb_level_index_t num_levels;
darray(struct xkb_kt_map_entry) map;
struct xkb_mods *preserve;
const char *name;
const char **level_names;
};

View File

@ -126,7 +126,6 @@
typedef struct _PreserveInfo {
struct list entry;
int matchingMapIndex;
xkb_mod_mask_t indexMods;
xkb_mod_mask_t preMods;
xkb_mod_mask_t indexVMods;
@ -564,7 +563,6 @@ AddPreserve(KeyTypesInfo *info, KeyTypeInfo *type,
}
*old = *new;
old->matchingMapIndex = -1;
list_append(&old->entry, &type->preserves);
return true;
@ -1054,7 +1052,9 @@ CopyDefToKeyType(KeyTypesInfo *info, KeyTypeInfo *def,
return false;
}
pre->matchingMapIndex = match - &darray_item(def->entries, 0);
match->preserve.mask = pre->preMods;
match->preserve.real_mods = pre->preMods;
match->preserve.vmods = pre->preVMods;
}
type->mods.real_mods = def->mask;
@ -1062,28 +1062,6 @@ CopyDefToKeyType(KeyTypesInfo *info, KeyTypeInfo *def,
type->num_levels = def->num_levels;
memcpy(&type->map, &def->entries, sizeof(def->entries));
if (!list_empty(&def->preserves)) {
type->preserve = calloc(darray_size(type->map),
sizeof(*type->preserve));
if (!type->preserve) {
log_warn(info->keymap->ctx,
"Couldn't allocate preserve array; "
"Preserve setting for type %s lost\n",
xkb_atom_text(keymap->ctx, def->name));
}
else {
list_foreach(pre, &def->preserves, entry) {
int ndx = pre->matchingMapIndex;
type->preserve[ndx].mask = pre->preMods;
type->preserve[ndx].real_mods = pre->preMods;
type->preserve[ndx].vmods = pre->preVMods;
}
}
}
else {
type->preserve = NULL;
}
type->name = xkb_atom_text(keymap->ctx, def->name);
if (!darray_empty(def->level_names)) {

View File

@ -355,7 +355,6 @@ xkb_map_unref(struct xkb_keymap *keymap)
darray_foreach(type, keymap->types) {
darray_free(type->map);
free(type->preserve);
free(type->level_names);
}
darray_free(keymap->types);