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
parent
6b75dd2dcb
commit
233d85c427
|
@ -346,6 +346,7 @@ write_types(struct xkb_keymap *keymap, struct buf *buf)
|
||||||
{
|
{
|
||||||
int n;
|
int n;
|
||||||
struct xkb_key_type *type;
|
struct xkb_key_type *type;
|
||||||
|
struct xkb_kt_map_entry *entry;
|
||||||
|
|
||||||
if (keymap->types_section_name)
|
if (keymap->types_section_name)
|
||||||
write_buf(buf, "\txkb_types \"%s\" {\n\n",
|
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,
|
get_mod_mask_text(keymap, type->mods.real_mods,
|
||||||
type->mods.vmods));
|
type->mods.vmods));
|
||||||
|
|
||||||
for (n = 0; n < darray_size(type->map); n++) {
|
darray_foreach(entry, type->map) {
|
||||||
struct xkb_kt_map_entry *entry = &darray_item(type->map, n);
|
|
||||||
char *str;
|
char *str;
|
||||||
|
|
||||||
str = get_mod_mask_text(keymap, entry->mods.real_mods,
|
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",
|
write_buf(buf, "\t\t\tmap[%s]= Level%d;\n",
|
||||||
str, entry->level + 1);
|
str, entry->level + 1);
|
||||||
|
|
||||||
if (!type->preserve || (!type->preserve[n].real_mods &&
|
if (!entry->preserve.real_mods && !entry->preserve.vmods)
|
||||||
!type->preserve[n].vmods))
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
write_buf(buf, "\t\t\tpreserve[%s]= ", str);
|
write_buf(buf, "\t\t\tpreserve[%s]= ", str);
|
||||||
write_buf(buf, "%s;\n",
|
write_buf(buf, "%s;\n",
|
||||||
get_mod_mask_text(keymap, type->preserve[n].real_mods,
|
get_mod_mask_text(keymap, entry->preserve.real_mods,
|
||||||
type->preserve[n].vmods));
|
entry->preserve.vmods));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (type->level_names) {
|
if (type->level_names) {
|
||||||
|
|
|
@ -244,13 +244,13 @@ struct xkb_mods {
|
||||||
struct xkb_kt_map_entry {
|
struct xkb_kt_map_entry {
|
||||||
xkb_level_index_t level;
|
xkb_level_index_t level;
|
||||||
struct xkb_mods mods;
|
struct xkb_mods mods;
|
||||||
|
struct xkb_mods preserve;
|
||||||
};
|
};
|
||||||
|
|
||||||
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;
|
darray(struct xkb_kt_map_entry) map;
|
||||||
struct xkb_mods *preserve;
|
|
||||||
const char *name;
|
const char *name;
|
||||||
const char **level_names;
|
const char **level_names;
|
||||||
};
|
};
|
||||||
|
|
|
@ -126,7 +126,6 @@
|
||||||
|
|
||||||
typedef struct _PreserveInfo {
|
typedef struct _PreserveInfo {
|
||||||
struct list entry;
|
struct list entry;
|
||||||
int matchingMapIndex;
|
|
||||||
xkb_mod_mask_t indexMods;
|
xkb_mod_mask_t indexMods;
|
||||||
xkb_mod_mask_t preMods;
|
xkb_mod_mask_t preMods;
|
||||||
xkb_mod_mask_t indexVMods;
|
xkb_mod_mask_t indexVMods;
|
||||||
|
@ -564,7 +563,6 @@ AddPreserve(KeyTypesInfo *info, KeyTypeInfo *type,
|
||||||
}
|
}
|
||||||
|
|
||||||
*old = *new;
|
*old = *new;
|
||||||
old->matchingMapIndex = -1;
|
|
||||||
list_append(&old->entry, &type->preserves);
|
list_append(&old->entry, &type->preserves);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -1054,7 +1052,9 @@ CopyDefToKeyType(KeyTypesInfo *info, KeyTypeInfo *def,
|
||||||
return false;
|
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;
|
type->mods.real_mods = def->mask;
|
||||||
|
@ -1062,28 +1062,6 @@ CopyDefToKeyType(KeyTypesInfo *info, KeyTypeInfo *def,
|
||||||
type->num_levels = def->num_levels;
|
type->num_levels = def->num_levels;
|
||||||
memcpy(&type->map, &def->entries, sizeof(def->entries));
|
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);
|
type->name = xkb_atom_text(keymap->ctx, def->name);
|
||||||
|
|
||||||
if (!darray_empty(def->level_names)) {
|
if (!darray_empty(def->level_names)) {
|
||||||
|
|
|
@ -355,7 +355,6 @@ xkb_map_unref(struct xkb_keymap *keymap)
|
||||||
|
|
||||||
darray_foreach(type, keymap->types) {
|
darray_foreach(type, keymap->types) {
|
||||||
darray_free(type->map);
|
darray_free(type->map);
|
||||||
free(type->preserve);
|
|
||||||
free(type->level_names);
|
free(type->level_names);
|
||||||
}
|
}
|
||||||
darray_free(keymap->types);
|
darray_free(keymap->types);
|
||||||
|
|
Loading…
Reference in New Issue