Commit 7ae0c6bac4759e9b56c4a5115c321b66012ce9dc

Ran Benita 2012-08-31T19:26:51

Convert rest of names in xkb_keymap back to atoms These were kept as atoms, but since the keymap was exposed in the API, we converted them to strings; no the keymap is no longer exposed, so we can go back to atoms. They make the keymap smaller (at least on 64-bit machines) and the comparisons faster. Signed-off-by: Ran Benita <ran234@gmail.com>

diff --git a/src/keymap-dump.c b/src/keymap-dump.c
index df1a3c2..6d00851 100644
--- a/src/keymap-dump.c
+++ b/src/keymap-dump.c
@@ -142,7 +142,8 @@ write_vmods(struct xkb_keymap *keymap, struct buf *buf)
             write_buf(buf, "\t\tvirtual_modifiers ");
         else
             write_buf(buf, ",");
-        write_buf(buf, "%s", keymap->vmod_names[i]);
+        write_buf(buf, "%s",
+                  xkb_atom_text(keymap->ctx, keymap->vmod_names[i]));
         num_vmods++;
     }
 
@@ -275,8 +276,8 @@ write_keycodes(struct xkb_keymap *keymap, struct buf *buf)
     for (i = 0; i < XkbNumIndicators; i++) {
         if (!keymap->indicator_names[i])
             continue;
-        write_buf(buf, "\t\tindicator %d = \"%s\";\n",
-                  i + 1, keymap->indicator_names[i]);
+        write_buf(buf, "\t\tindicator %d = \"%s\";\n", i + 1,
+                  xkb_atom_text(keymap->ctx, keymap->indicator_names[i]));
     }
 
 
@@ -356,7 +357,7 @@ write_indicator_map(struct xkb_keymap *keymap, struct buf *buf, int num)
     struct xkb_indicator_map *led = &keymap->indicators[num];
 
     write_buf(buf, "\t\tindicator \"%s\" {\n",
-              keymap->indicator_names[num]);
+              xkb_atom_text(keymap->ctx, keymap->indicator_names[num]));
 
     if (led->which_groups) {
         if (led->which_groups != XkbIM_UseEffective) {
@@ -564,7 +565,8 @@ write_compat(struct xkb_keymap *keymap, struct buf *buf)
 
         if (interp->virtual_mod != XKB_MOD_INVALID) {
             write_buf(buf, "\t\t\tvirtualModifier= %s;\n",
-                      keymap->vmod_names[interp->virtual_mod]);
+                      xkb_atom_text(keymap->ctx,
+                                    keymap->vmod_names[interp->virtual_mod]));
         }
 
         if (interp->match & XkbSI_LevelOneOnly)
@@ -648,7 +650,7 @@ write_symbols(struct xkb_keymap *keymap, struct buf *buf)
             continue;
         write_buf(buf,
                   "\t\tname[group%d]=\"%s\";\n", group + 1,
-                  keymap->group_names[group]);
+                  xkb_atom_text(keymap->ctx, keymap->group_names[group]));
         tmp++;
     }
     if (tmp > 0)
diff --git a/src/map.c b/src/map.c
index d133ae1..cff6368 100644
--- a/src/map.c
+++ b/src/map.c
@@ -137,7 +137,8 @@ xkb_map_mod_get_name(struct xkb_keymap *keymap, xkb_mod_index_t idx)
      * find a virtual mod name. */
     name = ModIndexToName(idx);
     if (!name)
-        name = keymap->vmod_names[idx - XkbNumModifiers];
+        name = xkb_atom_text(keymap->ctx,
+                             keymap->vmod_names[idx - XkbNumModifiers]);
 
     return name;
 }
@@ -149,13 +150,20 @@ XKB_EXPORT xkb_mod_index_t
 xkb_map_mod_get_index(struct xkb_keymap *keymap, const char *name)
 {
     xkb_mod_index_t i;
+    xkb_atom_t atom;
 
     i = ModNameToIndex(name);
     if (i != XKB_MOD_INVALID)
         return i;
 
-    for (i = 0; i < XkbNumVirtualMods && keymap->vmod_names[i]; i++) {
-        if (istreq(name, keymap->vmod_names[i]))
+    atom = xkb_atom_lookup(keymap->ctx, name);
+    if (atom == XKB_ATOM_NONE)
+        return XKB_MOD_INVALID;
+
+    for (i = 0; i < XkbNumVirtualMods; i++) {
+        if (keymap->vmod_names[i] == XKB_ATOM_NONE)
+            break;
+        if (keymap->vmod_names[i] == atom)
             return i + XkbNumModifiers;
     }
 
@@ -180,7 +188,7 @@ xkb_map_group_get_name(struct xkb_keymap *keymap, xkb_group_index_t idx)
     if (idx >= xkb_map_num_groups(keymap))
         return NULL;
 
-    return keymap->group_names[idx];
+    return xkb_atom_text(keymap->ctx, keymap->group_names[idx]);
 }
 
 /**
@@ -190,10 +198,14 @@ XKB_EXPORT xkb_group_index_t
 xkb_map_group_get_index(struct xkb_keymap *keymap, const char *name)
 {
     xkb_group_index_t num_groups = xkb_map_num_groups(keymap);
+    xkb_atom_t atom = xkb_atom_lookup(keymap->ctx, name);
     xkb_group_index_t i;
 
+    if (atom == XKB_ATOM_NONE)
+        return XKB_GROUP_INVALID;
+
     for (i = 0; i < num_groups; i++)
-        if (istreq(keymap->group_names[i], name))
+        if (keymap->group_names[i] == atom)
             return i;
 
     return XKB_GROUP_INVALID;
@@ -238,7 +250,7 @@ xkb_map_led_get_name(struct xkb_keymap *keymap, xkb_led_index_t idx)
     if (idx >= xkb_map_num_leds(keymap))
         return NULL;
 
-    return keymap->indicator_names[idx];
+    return xkb_atom_text(keymap->ctx, keymap->indicator_names[idx]);
 }
 
 /**
@@ -248,10 +260,14 @@ XKB_EXPORT xkb_group_index_t
 xkb_map_led_get_index(struct xkb_keymap *keymap, const char *name)
 {
     xkb_led_index_t num_leds = xkb_map_num_leds(keymap);
+    xkb_atom_t atom = xkb_atom_lookup(keymap->ctx, name);
     xkb_led_index_t i;
 
+    if (atom == XKB_ATOM_NONE)
+        return XKB_LED_INVALID;
+
     for (i = 0; i < num_leds; i++)
-        if (istreq(keymap->indicator_names[i], name))
+        if (keymap->indicator_names[i] == atom)
             return i;
 
     return XKB_LED_INVALID;
diff --git a/src/text.c b/src/text.c
index 12d90c4..38c2322 100644
--- a/src/text.c
+++ b/src/text.c
@@ -62,7 +62,7 @@ VModIndexText(struct xkb_keymap *keymap, xkb_mod_index_t ndx)
     if (ndx >= XkbNumVirtualMods)
          tmp = "illegal";
     else
-         tmp = keymap->vmod_names[ndx];
+         tmp = xkb_atom_text(keymap->ctx, keymap->vmod_names[ndx]);
 
     if (!tmp) {
         snprintf(buf, sizeof(buf) - 1, "%d", ndx);
diff --git a/src/xkb-priv.h b/src/xkb-priv.h
index e482ad1..a598e3c 100644
--- a/src/xkb-priv.h
+++ b/src/xkb-priv.h
@@ -343,14 +343,14 @@ struct xkb_keymap {
 
     /* vmod -> mod mapping */
     xkb_mod_mask_t vmods[XkbNumVirtualMods];
-    const char *vmod_names[XkbNumVirtualMods];
+    xkb_atom_t vmod_names[XkbNumVirtualMods];
 
     /* Number of groups in the key with the most groups. */
     xkb_group_index_t num_groups;
-    const char *group_names[XkbNumKbdGroups];
+    xkb_atom_t group_names[XkbNumKbdGroups];
 
     struct xkb_indicator_map indicators[XkbNumIndicators];
-    const char *indicator_names[XkbNumIndicators];
+    xkb_atom_t indicator_names[XkbNumIndicators];
 
     char *keycodes_section_name;
     char *symbols_section_name;
diff --git a/src/xkbcomp/compat.c b/src/xkbcomp/compat.c
index 0014029..dda930e 100644
--- a/src/xkbcomp/compat.c
+++ b/src/xkbcomp/compat.c
@@ -1012,15 +1012,13 @@ CopyIndicatorMapDefs(CompatInfo *info)
     struct xkb_keymap *keymap = info->keymap;
 
     darray_foreach(led, info->leds) {
-        const char *name = xkb_atom_text(keymap->ctx, led->name);
-
         /*
          * Find the indicator with the given name, if it was already
          * declared in keycodes.
          */
         im = NULL;
         for (i = 0; i < XkbNumIndicators; i++) {
-            if (streq_not_null(keymap->indicator_names[i], name)) {
+            if (keymap->indicator_names[i] == led->name) {
                 im = &keymap->indicators[i];
                 break;
             }
@@ -1030,13 +1028,14 @@ CopyIndicatorMapDefs(CompatInfo *info)
         if (!im) {
             log_dbg(keymap->ctx,
                     "Indicator name \"%s\" was not declared in the keycodes section; "
-                    "Adding new indicator\n", name);
+                    "Adding new indicator\n",
+                    xkb_atom_text(keymap->ctx, led->name));
 
             for (i = 0; i < XkbNumIndicators; i++) {
-                if (keymap->indicator_names[i])
+                if (keymap->indicator_names[i] != XKB_ATOM_NONE)
                     continue;
 
-                keymap->indicator_names[i] = name;
+                keymap->indicator_names[i] = led->name;
                 im = &keymap->indicators[i];
                 break;
             }
@@ -1046,7 +1045,8 @@ CopyIndicatorMapDefs(CompatInfo *info)
                 log_err(keymap->ctx,
                         "Too many indicators (maximum is %d); "
                         "Indicator name \"%s\" ignored\n",
-                        XkbNumIndicators, name);
+                        XkbNumIndicators,
+                        xkb_atom_text(keymap->ctx, led->name));
                 continue;
             }
         }
diff --git a/src/xkbcomp/keycodes.c b/src/xkbcomp/keycodes.c
index a2ae08d..0029eee 100644
--- a/src/xkbcomp/keycodes.c
+++ b/src/xkbcomp/keycodes.c
@@ -826,8 +826,7 @@ CopyKeyNamesToKeymap(struct xkb_keymap *keymap, KeyNamesInfo *info)
         if (led->name == XKB_ATOM_NONE)
             continue;
 
-        keymap->indicator_names[idx] =
-            xkb_atom_text(keymap->ctx, led->name);
+        keymap->indicator_names[idx] = led->name;
     }
 
     ApplyAliases(info, keymap);
diff --git a/src/xkbcomp/symbols.c b/src/xkbcomp/symbols.c
index e1dc463..79f5398 100644
--- a/src/xkbcomp/symbols.c
+++ b/src/xkbcomp/symbols.c
@@ -1933,12 +1933,9 @@ CompileSymbols(XkbFile *file, struct xkb_keymap *keymap,
     if (info.name)
         keymap->symbols_section_name = strdup(info.name);
 
-    for (i = 0; i < XkbNumKbdGroups; i++) {
-        if (info.groupNames[i] != XKB_ATOM_NONE) {
-            keymap->group_names[i] = xkb_atom_text(keymap->ctx,
-                                                   info.groupNames[i]);
-        }
-    }
+    for (i = 0; i < XkbNumKbdGroups; i++)
+        if (info.groupNames[i] != XKB_ATOM_NONE)
+            keymap->group_names[i] = info.groupNames[i];
 
     /* sanitize keys */
     darray_foreach(keyi, info.keys)
diff --git a/src/xkbcomp/vmod.c b/src/xkbcomp/vmod.c
index 5e7ad58..59c3b6d 100644
--- a/src/xkbcomp/vmod.c
+++ b/src/xkbcomp/vmod.c
@@ -71,8 +71,7 @@ HandleVModDef(VModDef *stmt, struct xkb_keymap *keymap,
         if (!keymap->vmod_names[i])
             continue;
 
-        if (!streq(keymap->vmod_names[i],
-                   xkb_atom_text(keymap->ctx, stmt->name)))
+        if (keymap->vmod_names[i] != stmt->name)
             continue;
 
         info->available |= bit;
@@ -89,7 +88,7 @@ HandleVModDef(VModDef *stmt, struct xkb_keymap *keymap,
     info->defined |= (1 << nextFree);
     info->available |= (1 << nextFree);
 
-    keymap->vmod_names[nextFree] = xkb_atom_text(keymap->ctx, stmt->name);
+    keymap->vmod_names[nextFree] = stmt->name;
     return true;
 }
 
@@ -98,13 +97,12 @@ LookupVModIndex(const struct xkb_keymap *keymap, xkb_atom_t field,
                 enum expr_value_type type, xkb_mod_index_t *val_rtrn)
 {
     xkb_mod_index_t i;
-    const char *name = xkb_atom_text(keymap->ctx, field);
 
     if (type != EXPR_TYPE_INT)
         return false;
 
     for (i = 0; i < XkbNumVirtualMods; i++) {
-        if (keymap->vmod_names[i] && streq(keymap->vmod_names[i], name)) {
+        if (keymap->vmod_names[i] == field) {
             *val_rtrn = i;
             return true;
         }
@@ -135,7 +133,7 @@ ResolveVirtualModifier(ExprDef *def, struct xkb_keymap *keymap,
                        xkb_mod_index_t *ndx_rtrn, VModInfo *info)
 {
     xkb_mod_index_t i;
-    const char *name;
+    xkb_atom_t name = def->value.str;
 
     if (def->op != EXPR_IDENT) {
         log_err(keymap->ctx,
@@ -145,11 +143,8 @@ ResolveVirtualModifier(ExprDef *def, struct xkb_keymap *keymap,
         return false;
     }
 
-    name = xkb_atom_text(keymap->ctx, def->value.str);
-
     for (i = 0; i < XkbNumVirtualMods; i++) {
-        if ((info->available & (1 << i)) &&
-            streq_not_null(keymap->vmod_names[i], name)) {
+        if ((info->available & (1 << i)) && keymap->vmod_names[i] == name) {
             *ndx_rtrn = i;
             return true;
         }
@@ -157,6 +152,7 @@ ResolveVirtualModifier(ExprDef *def, struct xkb_keymap *keymap,
 
     log_err(keymap->ctx,
             "Cannot resolve virtual modifier: "
-            "\"%s\" was not previously declared\n", name);
+            "\"%s\" was not previously declared\n",
+            xkb_atom_text(keymap->ctx, name));
     return false;
 }