From 8ccfee82ec7fbc36b8009bc1686783e920d7b879 Mon Sep 17 00:00:00 2001 From: Ran Benita Date: Tue, 7 Aug 2012 08:38:20 +0300 Subject: [PATCH] types: use regular array for types The current code doesn't resize it any more. Signed-off-by: Ran Benita --- src/keymap-dump.c | 12 +++++++----- src/xkb-priv.h | 5 +++-- src/xkbcomp/compat.c | 5 +++-- src/xkbcomp/keytypes.c | 25 +++++++++++++------------ src/xkbcomp/symbols.c | 8 +++----- src/xkbcomp/xkbcomp.c | 10 +++++----- 6 files changed, 34 insertions(+), 31 deletions(-) diff --git a/src/keymap-dump.c b/src/keymap-dump.c index 017d586..deeea36 100644 --- a/src/keymap-dump.c +++ b/src/keymap-dump.c @@ -344,7 +344,8 @@ write_keycodes(struct xkb_keymap *keymap, struct buf *buf) 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; @@ -356,7 +357,9 @@ write_types(struct xkb_keymap *keymap, struct buf *buf) 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", @@ -749,13 +752,12 @@ write_symbols(struct xkb_keymap *keymap, struct buf *buf) 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); } } diff --git a/src/xkb-priv.h b/src/xkb-priv.h index 256faf9..1b630c8 100644 --- a/src/xkb-priv.h +++ b/src/xkb-priv.h @@ -340,7 +340,8 @@ struct xkb_keymap { /* 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; @@ -391,7 +392,7 @@ static inline struct xkb_key_type * 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 diff --git a/src/xkbcomp/compat.c b/src/xkbcomp/compat.c index 064a7fe..33315ad 100644 --- a/src/xkbcomp/compat.c +++ b/src/xkbcomp/compat.c @@ -1473,7 +1473,7 @@ UpdateModifiersFromCompat(struct xkb_keymap *keymap) 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; @@ -1500,8 +1500,9 @@ UpdateModifiersFromCompat(struct xkb_keymap *keymap) } /* 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); diff --git a/src/xkbcomp/keytypes.c b/src/xkbcomp/keytypes.c index 5c0f63f..560d295 100644 --- a/src/xkbcomp/keytypes.c +++ b/src/xkbcomp/keytypes.c @@ -1078,7 +1078,7 @@ CompileKeyTypes(XkbFile *file, struct xkb_keymap *keymap, enum merge_mode merge) { unsigned int i; - struct xkb_key_type *type; + unsigned int num_types; KeyTypesInfo info; KeyTypeInfo *def; @@ -1092,23 +1092,24 @@ CompileKeyTypes(XkbFile *file, struct xkb_keymap *keymap, 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); diff --git a/src/xkbcomp/symbols.c b/src/xkbcomp/symbols.c index 62c9fd5..7067cc5 100644 --- a/src/xkbcomp/symbols.c +++ b/src/xkbcomp/symbols.c @@ -1486,14 +1486,12 @@ FindNamedType(struct xkb_keymap *keymap, xkb_atom_t atom, unsigned *type_rtrn) { 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; @@ -1753,7 +1751,7 @@ CopySymbolsDef(SymbolsInfo *info, KeyInfo *keyi, } /* 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; " diff --git a/src/xkbcomp/xkbcomp.c b/src/xkbcomp/xkbcomp.c index 3ca1d89..b79166b 100644 --- a/src/xkbcomp/xkbcomp.c +++ b/src/xkbcomp/xkbcomp.c @@ -347,17 +347,17 @@ xkb_map_ref(struct xkb_keymap *keymap) 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); -- 2.7.4