types: remove DeleteLevel1MapEntries
authorRan Benita <ran234@gmail.com>
Tue, 7 Aug 2012 05:17:26 +0000 (08:17 +0300)
committerRan Benita <ran234@gmail.com>
Tue, 7 Aug 2012 10:20:37 +0000 (13:20 +0300)
If there is no map entry for some modifier combination, the default is
to use level 1. The removed code is an optimization to save some space
by removing these entries. But it doesn't actually save any space, and
did not in fact remove all level 1 entries (it walks the array while
modifying it so there's an off-by-one error).

We can instead keep them in the types but just not print them in
keymap-dump.c, to get about the same behavior.

Signed-off-by: Ran Benita <ran234@gmail.com>
src/keymap-dump.c
src/xkbcomp/keytypes.c
test/data/keymaps/dump.data

index 5b8f66a..017d586 100644 (file)
@@ -366,6 +366,13 @@ write_types(struct xkb_keymap *keymap, struct buf *buf)
         darray_foreach(entry, type->map) {
             char *str;
 
+            /*
+             * Printing level 1 entries is redundant, it's the default,
+             * unless there's preserve info.
+             */
+            if (entry->level == 0 && entry->preserve.mask == 0)
+                continue;
+
             str = get_mod_mask_text(keymap, entry->mods.real_mods,
                                     entry->mods.vmods);
             write_buf(buf, "\t\t\tmap[%s]= Level%d;\n",
index a41df54..5c0f63f 100644 (file)
@@ -496,22 +496,6 @@ FindMatchingMapEntry(KeyTypeInfo * type, unsigned mask, unsigned vmask)
     return NULL;
 }
 
-static void
-DeleteLevel1MapEntries(KeyTypeInfo * type)
-{
-    unsigned int i, n;
-
-    /* TODO: Be just a bit more clever here. */
-    for (i = 0; i < darray_size(type->entries); i++) {
-        if (darray_item(type->entries, i).level == 0) {
-            for (n = i; n < darray_size(type->entries) - 1; n++)
-                darray_item(type->entries, n) =
-                    darray_item(type->entries, n + 1);
-            (void) darray_pop(type->entries);
-        }
-    }
-}
-
 static struct xkb_kt_map_entry *
 NextMapEntry(KeyTypesInfo *info, KeyTypeInfo * type)
 {
@@ -1114,8 +1098,6 @@ CompileKeyTypes(XkbFile *file, struct xkb_keymap *keymap,
     list_foreach(def, &info.types, entry) {
         type = &darray_item(keymap->types, i++);
 
-        DeleteLevel1MapEntries(def);
-
         if (!CopyDefToKeyType(&info, def, type))
             goto err_info;
     }
index 3c97dbc..631b0d3 100644 (file)
@@ -372,7 +372,6 @@ xkb_keymap {
                };
                type "LOCAL_EIGHT_LEVEL" {
                        modifiers= Shift+Lock+Control+LevelThree;
-                       map[Shift+Lock]= Level1;
                        map[Shift]= Level2;
                        map[Lock]= Level2;
                        map[LevelThree]= Level3;
@@ -518,7 +517,6 @@ xkb_keymap {
                };
                type "FOUR_LEVEL_MIXED_KEYPAD" {
                        modifiers= Shift+NumLock+LevelThree;
-                       map[Shift+NumLock]= Level1;
                        map[NumLock]= Level2;
                        map[Shift]= Level2;
                        map[LevelThree]= Level3;