Cuts out a lot of useless redirection and space.
Signed-off-by: Ran Benita <ran234@gmail.com>
}
if (key->explicit & XkbExplicitInterpretMask)
- showActions = XkbKeyHasActions(key);
+ showActions = (key->actions != NULL);
else
showActions = false;
write_buf(buf, " ] };\n");
}
else {
- union xkb_action *acts;
- int level;
+ xkb_level_index_t level;
- acts = XkbKeyActionsPtr(keymap, key);
for (group = 0; group < key->num_groups; group++) {
if (group != 0)
write_buf(buf, ",");
level++) {
if (level != 0)
write_buf(buf, ", ");
- write_action(keymap, buf, &acts[level], NULL, NULL);
+ write_action(keymap, buf,
+ XkbKeyActionEntry(key, group, level),
+ NULL, NULL);
}
write_buf(buf, " ]");
- acts += key->width;
}
}
write_buf(buf, "\n\t\t};\n");
if (XkbKeycodeInRange(state->keymap, kc))
key = XkbKey(state->keymap, kc);
- if (!key || !XkbKeyHasActions(key))
+ if (!key || !key->actions)
return &fake;
group = xkb_key_get_group(state, kc);
if (level == XKB_LEVEL_INVALID)
return &fake;
- return XkbKeyActionEntry(state->keymap, key, group, level);
+ return XkbKeyActionEntry(key, group, level);
}
static struct xkb_filter *
bool repeats;
- /* Index into keymap->acts */
- size_t acts_index;
+ union xkb_action *actions;
unsigned char kt_index[XkbNumKbdGroups];
struct xkb_mods groups[XkbNumKbdGroups];
const char *group_names[XkbNumKbdGroups];
- darray(union xkb_action) acts;
-
struct xkb_indicator_map indicators[XkbNumIndicators];
const char *indicator_names[XkbNumIndicators];
return XkbKeySym(key, XkbKeySymOffset(key, group, level));
}
-static inline bool
-XkbKeyHasActions(struct xkb_key *key)
-{
- return key->acts_index != 0;
-}
-
-static inline unsigned int
-XkbKeyNumActions(struct xkb_key *key)
-{
- if (XkbKeyHasActions(key))
- return key->width * key->num_groups;
- return 1;
-}
-
-static inline union xkb_action *
-XkbKeyActionsPtr(struct xkb_keymap *keymap, struct xkb_key *key)
-{
- return darray_mem(keymap->acts, key->acts_index);
-}
-
static inline union xkb_action *
-XkbKeyActionEntry(struct xkb_keymap *keymap, struct xkb_key *key,
- xkb_group_index_t group, xkb_level_index_t level)
+XkbKeyActionEntry(struct xkb_key *key, xkb_group_index_t group,
+ xkb_level_index_t level)
{
- if (XkbKeyHasActions(key))
- return &XkbKeyActionsPtr(keymap, key)[key->width * group + level];
- return NULL;
+ return &key->actions[key->width * group + level];
}
static inline bool
old->next = new;
return true;
}
-
-/***====================================================================***/
-
-union xkb_action *
-ResizeKeyActions(struct xkb_keymap *keymap, struct xkb_key *key,
- uint32_t needed)
-{
- size_t old_ndx, old_num_acts, new_ndx;
-
- if (needed == 0) {
- key->acts_index = 0;
- return NULL;
- }
-
- if (XkbKeyHasActions(key) && key->width >= needed)
- return XkbKeyActionsPtr(keymap, key);
-
- /*
- * The key may already be in the array, but without enough space.
- * This should not happen often, so in order to avoid moving and
- * copying stuff from acts and key_acts, we just allocate new
- * space for the key at the end, and leave the old space alone.
- */
-
- old_ndx = key->acts_index;
- old_num_acts = XkbKeyNumActions(key);
- new_ndx = darray_size(keymap->acts);
-
- darray_resize0(keymap->acts, new_ndx + needed);
- key->acts_index = new_ndx;
-
- /*
- * The key was already in the array, copy the old actions to the
- * new space.
- */
- if (old_ndx != 0)
- memcpy(darray_mem(keymap->acts, new_ndx),
- darray_mem(keymap->acts, old_ndx),
- old_num_acts * sizeof(union xkb_action));
-
- return XkbKeyActionsPtr(keymap, key);
-}
ExprDef *index, ExprDef *value,
ActionInfo **info_rtrn);
-union xkb_action *
-ResizeKeyActions(struct xkb_keymap *keymap, struct xkb_key *key,
- uint32_t needed);
-
extern const LookupEntry ctrlNames[];
#endif /* ACTION_H */
{
#define INTERP_SIZE (8 * 4)
struct xkb_sym_interpret *interps[INTERP_SIZE];
- union xkb_action *acts;
xkb_mod_mask_t vmodmask = 0;
int num_acts = 0;
xkb_group_index_t group;
}
}
- if (num_acts)
- num_acts = key->num_groups * key->width;
- acts = ResizeKeyActions(keymap, key, num_acts);
- if (num_acts && !acts)
- return false;
+ if (num_acts && !key->actions) {
+ key->actions = calloc(key->num_groups * key->width,
+ sizeof(*key->actions));
+ if (!key->actions)
+ return false;
+ }
for (group = 0; group < key->num_groups; group++) {
for (level = 0; level < XkbKeyGroupWidth(keymap, key, group);
if (interp->virtual_mod != XkbNoModifier)
vmodmask |= (1 << interp->virtual_mod);
}
- acts[i] = interp->act;
+
+ key->actions[i] = interp->act;
}
}
/* Update action modifiers. */
xkb_foreach_key(key, keymap) {
- union xkb_action *acts = XkbKeyActionsPtr(keymap, key);
- for (i = 0; i < XkbKeyNumActions(key); i++)
- UpdateActionMods(keymap, &acts[i], key->modmap);
+ if (!key->actions)
+ continue;
+
+ for (i = 0; i < key->num_groups * key->width; i++)
+ UpdateActionMods(keymap, &key->actions[i], key->modmap);
}
/* Update group modifiers. */
struct xkb_key_type * type;
bool haveActions, autoType, useAlias;
unsigned types[XkbNumKbdGroups];
- union xkb_action *outActs;
unsigned int symIndex = 0;
useAlias = (start_from == 0);
darray_resize0(key->syms, sizeSyms);
+ key->num_groups = nGroups;
+
+ key->width = width;
+
+ key->sym_index = calloc(nGroups * width, sizeof(*key->sym_index));
+
+ key->num_syms = calloc(nGroups * width, sizeof(*key->num_syms));
+
if (haveActions) {
- outActs = ResizeKeyActions(keymap, key, width * nGroups);
- if (outActs == NULL) {
- log_wsgo(info->keymap->ctx,
- "Could not enlarge actions for %s (key %d)\n",
- LongKeyNameText(keyi->name), kc);
- return false;
- }
+ key->actions = calloc(nGroups * width, sizeof(*key->actions));
key->explicit |= XkbExplicitInterpretMask;
}
- else
- outActs = NULL;
- key->num_groups = nGroups;
if (keyi->defined & KEY_FIELD_GROUPINFO) {
key->out_of_range_group_number = keyi->out_of_range_group_number;
key->out_of_range_group_action = keyi->out_of_range_group_action;
}
- key->width = width;
- key->sym_index = calloc(nGroups * width, sizeof(*key->sym_index));
- key->num_syms = calloc(nGroups * width, sizeof(*key->num_syms));
for (i = 0; i < nGroups; i++) {
/* assign kt_index[i] to the index of the type in map->types.
key->sym_index[(i * width) + tmp] = -1;
key->num_syms[(i * width) + tmp] = 0;
}
- if (outActs != NULL && !darray_empty(keyi->acts[i])) {
+ if (key->actions && !darray_empty(keyi->acts[i])) {
if (tmp < keyi->numLevels[i])
- outActs[tmp] = darray_item(keyi->acts[i], tmp);
+ key->actions[tmp] = darray_item(keyi->acts[i], tmp);
else
- outActs[tmp].type = XkbSA_NoAction;
+ key->actions[tmp].type = XkbSA_NoAction;
}
}
}
if (info.errorCount != 0)
goto err_info;
- darray_resize0(keymap->acts, darray_size(keymap->acts) + 32 + 1);
-
if (info.name)
keymap->symbols_section_name = strdup(info.name);
free(key->sym_index);
free(key->num_syms);
darray_free(key->syms);
+ free(key->actions);
}
darray_free(keymap->keys);
- darray_free(keymap->acts);
-
darray_free(keymap->sym_interpret);
darray_free(keymap->key_aliases);