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>
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 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327
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;
}