Commit b2fba7305c33e04abce550245f1ae7fcdcad3a2a

Ran Benita 2012-08-07T08:52:23

types: use regular array for map entries This array is only initialized once. Signed-off-by: Ran Benita <ran234@gmail.com>

diff --git a/src/keymap-dump.c b/src/keymap-dump.c
index deeea36..b2a08b6 100644
--- a/src/keymap-dump.c
+++ b/src/keymap-dump.c
@@ -344,7 +344,7 @@ write_keycodes(struct xkb_keymap *keymap, struct buf *buf)
 static bool
 write_types(struct xkb_keymap *keymap, struct buf *buf)
 {
-    unsigned int i;
+    unsigned int i, j;
     xkb_level_index_t n;
     struct xkb_key_type *type;
     struct xkb_kt_map_entry *entry;
@@ -366,8 +366,9 @@ write_types(struct xkb_keymap *keymap, struct buf *buf)
                   get_mod_mask_text(keymap, type->mods.real_mods,
                                     type->mods.vmods));
 
-        darray_foreach(entry, type->map) {
+        for (j = 0; j < type->num_entries; j++) {
             char *str;
+            entry = &type->map[j];
 
             /*
              * Printing level 1 entries is redundant, it's the default,
diff --git a/src/map.c b/src/map.c
index d602c90..b0d077f 100644
--- a/src/map.c
+++ b/src/map.c
@@ -219,7 +219,7 @@ xkb_key_get_level(struct xkb_state *state, xkb_keycode_t kc,
 {
     struct xkb_keymap *keymap = xkb_state_get_map(state);
     struct xkb_key_type *type;
-    struct xkb_kt_map_entry *entry;
+    unsigned int i;
     xkb_mod_mask_t active_mods;
 
     if (!XkbKeycodeInRange(keymap, kc))
@@ -229,10 +229,9 @@ xkb_key_get_level(struct xkb_state *state, xkb_keycode_t kc,
     active_mods = xkb_state_serialize_mods(state, XKB_STATE_EFFECTIVE);
     active_mods &= type->mods.mask;
 
-    darray_foreach(entry, type->map) {
-        if (entry->mods.mask == active_mods)
-            return entry->level;
-    }
+    for (i = 0; i < type->num_entries; i++)
+        if (type->map[i].mods.mask == active_mods)
+            return type->map[i].level;
 
     return 0;
 }
diff --git a/src/xkb-priv.h b/src/xkb-priv.h
index 1b630c8..95b243e 100644
--- a/src/xkb-priv.h
+++ b/src/xkb-priv.h
@@ -250,7 +250,8 @@ struct xkb_kt_map_entry {
 struct xkb_key_type {
     struct xkb_mods mods;
     xkb_level_index_t num_levels;
-    darray(struct xkb_kt_map_entry) map;
+    struct xkb_kt_map_entry *map;
+    unsigned int num_entries;
     const char *name;
     const char **level_names;
 };
diff --git a/src/xkbcomp/compat.c b/src/xkbcomp/compat.c
index 33315ad..9007180 100644
--- a/src/xkbcomp/compat.c
+++ b/src/xkbcomp/compat.c
@@ -1473,10 +1473,9 @@ UpdateModifiersFromCompat(struct xkb_keymap *keymap)
     xkb_mod_index_t vmod;
     xkb_group_index_t grp;
     xkb_led_index_t led;
-    unsigned int i;
+    unsigned int i, j;
     struct xkb_key *key;
     struct xkb_key_type *type;
-    struct xkb_kt_map_entry *entry;
 
     /* Find all the interprets for the key and bind them to actions,
      * which will also update the vmodmap. */
@@ -1513,9 +1512,12 @@ UpdateModifiersFromCompat(struct xkb_keymap *keymap)
             mask |= keymap->vmods[vmod];
         }
 
-        darray_foreach(entry, type->map)
-            entry->mods.mask = entry->mods.real_mods |
-                               VModsToReal(keymap, entry->mods.vmods);
+        for (j = 0; j < type->num_entries; j++) {
+            type->map[j].mods.mask = 0;
+            type->map[j].mods.mask |= type->map[j].mods.real_mods;
+            type->map[j].mods.mask |= VModsToReal(keymap,
+                                                  type->map[j].mods.vmods);
+        }
     }
 
     /* Update action modifiers. */
diff --git a/src/xkbcomp/keytypes.c b/src/xkbcomp/keytypes.c
index 560d295..3f6a290 100644
--- a/src/xkbcomp/keytypes.c
+++ b/src/xkbcomp/keytypes.c
@@ -989,25 +989,31 @@ HandleKeyTypesFile(KeyTypesInfo *info, XkbFile *file, enum merge_mode merge)
 static bool
 ComputeEffectiveMap(struct xkb_keymap *keymap, struct xkb_key_type *type)
 {
-    uint32_t tmp;
+    unsigned int i;
+    xkb_mod_mask_t tmp;
     struct xkb_kt_map_entry *entry = NULL;
 
     if (type->mods.vmods != 0) {
         tmp = VModsToReal(keymap, type->mods.vmods);
         type->mods.mask = tmp | type->mods.real_mods;
-        darray_foreach(entry, type->map) {
+
+        for (i = 0; i < type->num_entries; i++) {
+            entry = &type->map[i];
             tmp = 0;
+
             if (entry->mods.vmods != 0) {
                 tmp = VModsToReal(keymap, entry->mods.vmods);
                 if (tmp == 0)
                     continue;
             }
+
             entry->mods.mask =
                 (entry->mods.real_mods | tmp) & type->mods.mask;
         }
     }
-    else
+    else {
         type->mods.mask = type->mods.real_mods;
+    }
 
     return true;
 }
@@ -1044,7 +1050,9 @@ CopyDefToKeyType(KeyTypesInfo *info, KeyTypeInfo *def,
     type->mods.real_mods = def->mask;
     type->mods.vmods = def->vmask;
     type->num_levels = def->num_levels;
-    memcpy(&type->map, &def->entries, sizeof(def->entries));
+    type->map = darray_mem(def->entries, 0);
+    type->num_entries = darray_size(def->entries);
+    darray_init(def->entries);
 
     type->name = xkb_atom_text(keymap->ctx, def->name);
 
@@ -1069,7 +1077,6 @@ CopyDefToKeyType(KeyTypesInfo *info, KeyTypeInfo *def,
         type->level_names = NULL;
     }
 
-    darray_init(def->entries);
     return ComputeEffectiveMap(keymap, type);
 }
 
diff --git a/src/xkbcomp/xkbcomp.c b/src/xkbcomp/xkbcomp.c
index b79166b..2932ba3 100644
--- a/src/xkbcomp/xkbcomp.c
+++ b/src/xkbcomp/xkbcomp.c
@@ -354,7 +354,7 @@ xkb_map_unref(struct xkb_keymap *keymap)
         return;
 
     for (i = 0; i < keymap->num_types; i++) {
-        darray_free(keymap->types[i].map);
+        free(keymap->types[i].map);
         free(keymap->types[i].level_names);
     }
     free(keymap->types);