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>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190
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);
}