Commit 1a9968839eb6e1778616c33079fbee647a7ad087

Ran Benita 2012-08-31T19:05:49

expr: make ResolveString return an atom Almost all callers do xkb_atom_intern on the currently returned string, while ResolveString converts the atom to the string to begin with... uselss double work. Signed-off-by: Ran Benita <ran234@gmail.com>

diff --git a/src/xkbcomp/action.c b/src/xkbcomp/action.c
index f144100..ad8f42a 100644
--- a/src/xkbcomp/action.c
+++ b/src/xkbcomp/action.c
@@ -924,12 +924,14 @@ HandleActionMessage(struct xkb_keymap *keymap, union xkb_action *action,
         return true;
     }
     else if (field == ACTION_FIELD_DATA && !array_ndx) {
+        xkb_atom_t val;
         const char *str;
         int len;
 
-        if (!ExprResolveString(keymap->ctx, value, &str))
+        if (!ExprResolveString(keymap->ctx, value, &val))
             return ReportMismatch(keymap, action->type, field, "string");
 
+        str = xkb_atom_text(keymap->ctx, val);
         len = strlen(str);
         if (len < 1 || len > 6) {
             log_warn(keymap->ctx,
@@ -1152,12 +1154,14 @@ HandlePrivate(struct xkb_keymap *keymap, union xkb_action *action,
     }
     else if (field == ACTION_FIELD_DATA) {
         if (array_ndx == NULL) {
+            xkb_atom_t val;
             const char *str;
             int len;
 
-            if (!ExprResolveString(keymap->ctx, value, &str))
+            if (!ExprResolveString(keymap->ctx, value, &val))
                 return ReportMismatch(keymap, action->type, field, "string");
 
+            str = xkb_atom_text(keymap->ctx, val);
             len = strlen(str);
             if (len < 1 || len > 7) {
                 log_warn(keymap->ctx,
diff --git a/src/xkbcomp/expr.c b/src/xkbcomp/expr.c
index a66f119..0ad6c60 100644
--- a/src/xkbcomp/expr.c
+++ b/src/xkbcomp/expr.c
@@ -475,7 +475,7 @@ ExprResolveButton(struct xkb_context *ctx, const ExprDef *expr, int *btn_rtrn)
 
 bool
 ExprResolveString(struct xkb_context *ctx, const ExprDef *expr,
-                  const char **val_rtrn)
+                  xkb_atom_t *val_rtrn)
 {
     switch (expr->op) {
     case EXPR_VALUE:
@@ -485,7 +485,7 @@ ExprResolveString(struct xkb_context *ctx, const ExprDef *expr,
             return false;
         }
 
-        *val_rtrn = xkb_atom_text(ctx, expr->value.str);
+        *val_rtrn = expr->value.str;
         return true;
 
     case EXPR_IDENT:
diff --git a/src/xkbcomp/expr.h b/src/xkbcomp/expr.h
index 3951095..3d8f5c1 100644
--- a/src/xkbcomp/expr.h
+++ b/src/xkbcomp/expr.h
@@ -83,7 +83,7 @@ ExprResolveButton(struct xkb_context *ctx, const ExprDef *expr,
 
 bool
 ExprResolveString(struct xkb_context *ctx, const ExprDef *expr,
-                  const char **val_rtrn);
+                  xkb_atom_t *val_rtrn);
 
 bool
 ExprResolveKeyName(struct xkb_context *ctx, const ExprDef *expr,
diff --git a/src/xkbcomp/keycodes.c b/src/xkbcomp/keycodes.c
index 49d07a6..a2ae08d 100644
--- a/src/xkbcomp/keycodes.c
+++ b/src/xkbcomp/keycodes.c
@@ -673,7 +673,7 @@ HandleIndicatorNameDef(KeyNamesInfo *info, IndicatorNameDef *def,
                        enum merge_mode merge)
 {
     IndicatorNameInfo ii;
-    const char *str;
+    xkb_atom_t name;
 
     if (def->ndx < 1 || def->ndx > XkbNumIndicators) {
         info->errorCount++;
@@ -683,7 +683,7 @@ HandleIndicatorNameDef(KeyNamesInfo *info, IndicatorNameDef *def,
         return false;
     }
 
-    if (!ExprResolveString(info->ctx, def->name, &str)) {
+    if (!ExprResolveString(info->ctx, def->name, &name)) {
         char buf[20];
         snprintf(buf, sizeof(buf), "%d", def->ndx);
         info->errorCount++;
@@ -693,7 +693,7 @@ HandleIndicatorNameDef(KeyNamesInfo *info, IndicatorNameDef *def,
 
     ii.merge = info->merge;
     ii.file_id = info->file_id;
-    ii.name = xkb_atom_intern(info->ctx, str);
+    ii.name = name;
     return AddIndicatorName(info, merge, &ii, def->ndx - 1);
 }
 
diff --git a/src/xkbcomp/symbols.c b/src/xkbcomp/symbols.c
index b245201..e1dc463 100644
--- a/src/xkbcomp/symbols.c
+++ b/src/xkbcomp/symbols.c
@@ -1030,19 +1030,19 @@ SetSymbolsField(SymbolsInfo *info, KeyInfo *keyi, const char *field,
 
     if (istreq(field, "type")) {
         xkb_group_index_t ndx;
-        const char *str;
+        xkb_atom_t val;
 
-        if (!ExprResolveString(ctx, value, &str))
-            log_vrb(info->keymap->ctx, 1,
+        if (!ExprResolveString(ctx, value, &val))
+            log_vrb(ctx, 1,
                     "The type field of a key symbol map must be a string; "
                     "Ignoring illegal type definition\n");
 
         if (arrayNdx == NULL) {
-            keyi->dfltType = xkb_atom_intern(ctx, str);
+            keyi->dfltType = val;
             keyi->defined |= KEY_FIELD_TYPE_DFLT;
         }
         else if (!ExprResolveGroup(ctx, arrayNdx, &ndx)) {
-            log_err(info->keymap->ctx,
+            log_err(ctx,
                     "Illegal group index for type of key %s; "
                     "Definition with non-integer array index ignored\n",
                     LongKeyNameText(keyi->name));
@@ -1050,7 +1050,7 @@ SetSymbolsField(SymbolsInfo *info, KeyInfo *keyi, const char *field,
         }
         else {
             ndx--;
-            keyi->types[ndx] = xkb_atom_intern(ctx, str);
+            keyi->types[ndx] = val;
             keyi->typesDefined |= (1 << ndx);
         }
     }
@@ -1184,7 +1184,7 @@ static int
 SetGroupName(SymbolsInfo *info, ExprDef *arrayNdx, ExprDef *value)
 {
     xkb_group_index_t grp;
-    const char *name;
+    xkb_atom_t name;
 
     if (!arrayNdx) {
         log_vrb(info->keymap->ctx, 1,
@@ -1207,9 +1207,7 @@ SetGroupName(SymbolsInfo *info, ExprDef *arrayNdx, ExprDef *value)
         return false;
     }
 
-    info->groupNames[grp - 1 + info->explicit_group] =
-        xkb_atom_intern(info->keymap->ctx, name);
-
+    info->groupNames[grp - 1 + info->explicit_group] = name;
     return true;
 }
 
diff --git a/src/xkbcomp/types.c b/src/xkbcomp/types.c
index fa6da56..4fb0c2f 100644
--- a/src/xkbcomp/types.c
+++ b/src/xkbcomp/types.c
@@ -635,7 +635,6 @@ SetLevelName(KeyTypesInfo *info, KeyTypeInfo *type, ExprDef *arrayNdx,
     xkb_level_index_t level;
     xkb_atom_t level_name;
     struct xkb_context *ctx = info->keymap->ctx;
-    const char *str;
 
     if (arrayNdx == NULL)
         return ReportTypeShouldBeArray(info, type, "level name");
@@ -643,7 +642,7 @@ SetLevelName(KeyTypesInfo *info, KeyTypeInfo *type, ExprDef *arrayNdx,
     if (!ExprResolveLevel(ctx, arrayNdx, &level))
         return ReportTypeBadType(info, type, "level name", "integer");
 
-    if (!ExprResolveString(ctx, value, &str)) {
+    if (!ExprResolveString(ctx, value, &level_name)) {
         log_err(info->keymap->ctx,
                 "Non-string name for level %d in key type %s; "
                 "Ignoring illegal level name definition\n",
@@ -651,8 +650,6 @@ SetLevelName(KeyTypesInfo *info, KeyTypeInfo *type, ExprDef *arrayNdx,
         return false;
     }
 
-    level_name = xkb_atom_intern(ctx, str);
-
     return AddLevelName(info, type, level, level_name, true);
 }