The current code doesn't resize it any more.
Signed-off-by: Ran Benita <ran234@gmail.com>
static bool
write_types(struct xkb_keymap *keymap, struct buf *buf)
{
- int n;
+ unsigned int i;
+ xkb_level_index_t n;
struct xkb_key_type *type;
struct xkb_kt_map_entry *entry;
write_vmods(keymap, buf);
- darray_foreach(type, keymap->types) {
+ for (i = 0; i < keymap->num_types; i++) {
+ type = &keymap->types[i];
+
write_buf(buf, "\t\ttype \"%s\" {\n",
type->name);
write_buf(buf, "\t\t\tmodifiers= %s;\n",
continue;
type = XkbKeyTypeIndex(key, group);
write_buf(buf, "\n\t\t\ttype[group%u]= \"%s\",",
- group + 1,
- darray_item(keymap->types, type).name);
+ group + 1, keymap->types[type].name);
}
}
else {
write_buf(buf, "\n\t\t\ttype= \"%s\",",
- darray_item(keymap->types, type).name);
+ keymap->types[type].name);
}
}
/* aliases in no particular order */
darray(struct xkb_key_alias) key_aliases;
- darray(struct xkb_key_type) types;
+ struct xkb_key_type *types;
+ unsigned int num_types;
darray(struct xkb_sym_interpret) sym_interpret;
XkbKeyType(struct xkb_keymap *keymap, struct xkb_key *key,
xkb_group_index_t group)
{
- return &darray_item(keymap->types, XkbKeyTypeIndex(key, group));
+ return &keymap->types[XkbKeyTypeIndex(key, group)];
}
static inline xkb_level_index_t
xkb_mod_index_t vmod;
xkb_group_index_t grp;
xkb_led_index_t led;
- int i;
+ unsigned int i;
struct xkb_key *key;
struct xkb_key_type *type;
struct xkb_kt_map_entry *entry;
}
/* Now update the level masks for all the types to reflect the vmods. */
- darray_foreach(type, keymap->types) {
+ for (i = 0; i < keymap->num_types; i++) {
xkb_mod_mask_t mask = 0;
+ type = &keymap->types[i];
type->mods.mask = type->mods.real_mods;
type->mods.mask |= VModsToReal(keymap, type->mods.vmods);
enum merge_mode merge)
{
unsigned int i;
- struct xkb_key_type *type;
+ unsigned int num_types;
KeyTypesInfo info;
KeyTypeInfo *def;
if (info.name)
keymap->types_section_name = strdup(info.name);
- darray_resize0(keymap->types, info.num_types ? info.num_types : 1);
-
- i = 0;
- list_foreach(def, &info.types, entry) {
- type = &darray_item(keymap->types, i++);
-
- if (!CopyDefToKeyType(&info, def, type))
- goto err_info;
- }
+ num_types = info.num_types ? info.num_types : 1;
+ keymap->types = calloc(num_types, sizeof(*keymap->types));
+ if (!keymap->types)
+ goto err_info;
+ keymap->num_types = num_types;
/*
* If no types were specified, the default unnamed one-level type is
* used for all keys.
*/
- if (i == 0) {
- if (!CopyDefToKeyType(&info, &info.dflt, &darray_item(keymap->types, 0)))
+ if (info.num_types == 0) {
+ if (!CopyDefToKeyType(&info, &info.dflt, &keymap->types[0]))
goto err_info;
+ } else {
+ i = 0;
+ list_foreach(def, &info.types, entry)
+ if (!CopyDefToKeyType(&info, def, &keymap->types[i++]))
+ goto err_info;
}
FreeKeyTypesInfo(&info);
{
unsigned n = 0;
const char *name = xkb_atom_text(keymap->ctx, atom);
- struct xkb_key_type *type;
- darray_foreach(type, keymap->types) {
- if (streq(type->name, name)) {
+ for (n = 0; n < keymap->num_types; n++) {
+ if (streq(keymap->types[n].name, name)) {
*type_rtrn = n;
return true;
}
- n++;
}
return false;
}
/* if the type specifies fewer levels than the key has, shrink the key */
- type = &darray_item(keymap->types, types[i]);
+ type = &keymap->types[types[i]];
if (type->num_levels < keyi->numLevels[i]) {
log_lvl(info->keymap->ctx, 1,
"Type \"%s\" has %d levels, but %s has %d symbols; "
XKB_EXPORT void
xkb_map_unref(struct xkb_keymap *keymap)
{
- struct xkb_key_type *type;
+ unsigned int i;
struct xkb_key *key;
if (!keymap || --keymap->refcnt > 0)
return;
- darray_foreach(type, keymap->types) {
- darray_free(type->map);
- free(type->level_names);
+ for (i = 0; i < keymap->num_types; i++) {
+ darray_free(keymap->types[i].map);
+ free(keymap->types[i].level_names);
}
- darray_free(keymap->types);
+ free(keymap->types);
darray_foreach(key, keymap->keys) {
free(key->sym_index);