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>
master
Ran Benita 2012-08-31 19:05:49 +03:00
parent 7aa31097bf
commit 1a9968839e
6 changed files with 21 additions and 22 deletions

View File

@ -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,

View File

@ -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:

View File

@ -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,

View File

@ -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);
}

View File

@ -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;
}

View File

@ -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);
}