Commit e8a6a5f09afa725b4ebc72eddb6e38740f3e5fda

Ran Benita 2012-07-15T10:38:05

Add common xkb_key struct Instead of having a million arrays from the keycode to various key-specific info in the keymap, add a single struct xkb_key to hold all of the data for the key in one object. This way we can pass it around, do some refactoring and make the code simpler. It's also nice to see everything in one place. The keys array is still indexed by keycode, which is suboptimal because there may be a lot of holes (i.e. unused keycodes between min_key_code and max_key_code). By the end of this series it would be abstracted enough to replace it by a hash table or similar if there's ever a need. 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
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
diff --git a/src/alloc.c b/src/alloc.c
index caf28e0..97ca82b 100644
--- a/src/alloc.c
+++ b/src/alloc.c
@@ -70,7 +70,7 @@ bool
 XkbcResizeKeySyms(struct xkb_keymap *keymap, xkb_keycode_t kc,
                   unsigned int needed)
 {
-    darray_resize0(darray_item(keymap->key_sym_map, kc).syms, needed);
+    darray_resize0(XkbKey(keymap, kc)->sym_map.syms, needed);
     return true;
 }
 
@@ -80,8 +80,10 @@ XkbcResizeKeyActions(struct xkb_keymap *keymap, xkb_keycode_t kc,
 {
     size_t old_ndx, old_num_acts, new_ndx;
 
+    key = XkbKey(keymap, kc);
+
     if (needed == 0) {
-        darray_item(keymap->key_acts, kc) = 0;
+        key->acts_index = 0;
         return NULL;
     }
 
@@ -96,12 +98,12 @@ XkbcResizeKeyActions(struct xkb_keymap *keymap, xkb_keycode_t kc,
      * space for the key at the end, and leave the old space alone.
      */
 
-    old_ndx = darray_item(keymap->key_acts, kc);
+    old_ndx = key->acts_index;
     old_num_acts = XkbKeyNumActions(keymap, kc);
     new_ndx = darray_size(keymap->acts);
 
     darray_resize0(keymap->acts, new_ndx + needed);
-    darray_item(keymap->key_acts, kc) = new_ndx;
+    key->acts_index = new_ndx;
 
     /*
      * The key was already in the array, copy the old actions to the
@@ -135,14 +137,13 @@ free_types(struct xkb_keymap *keymap)
 static void
 free_sym_maps(struct xkb_keymap *keymap)
 {
-    struct xkb_sym_map *sym_map;
+    struct xkb_key *key;
 
-    darray_foreach(sym_map, keymap->key_sym_map) {
-        free(sym_map->sym_index);
-        free(sym_map->num_syms);
-        darray_free(sym_map->syms);
+    darray_foreach(key, keymap->keys) {
+        free(key->sym_map.sym_index);
+        free(key->sym_map.num_syms);
+        darray_free(key->sym_map.syms);
     }
-    darray_free(keymap->key_sym_map);
 }
 
 static void
@@ -159,7 +160,6 @@ free_names(struct xkb_keymap *keymap)
     for (i = 0; i < XkbNumKbdGroups; i++)
         free(keymap->group_names[i]);
 
-    darray_free(keymap->key_names);
     darray_free(keymap->key_aliases);
 
     free(keymap->keycodes_section_name);
@@ -191,15 +191,10 @@ XkbcFreeKeyboard(struct xkb_keymap *keymap)
 
     free_types(keymap);
     free_sym_maps(keymap);
-    free(keymap->modmap);
-    free(keymap->explicit);
-    darray_free(keymap->key_acts);
     darray_free(keymap->acts);
-    free(keymap->behaviors);
-    free(keymap->vmodmap);
     darray_free(keymap->sym_interpret);
     free_names(keymap);
-    free(keymap->per_key_repeat);
+    darray_free(keymap->keys);
     xkb_context_unref(keymap->ctx);
     free(keymap);
 }
diff --git a/src/keymap-dump.c b/src/keymap-dump.c
index b44a909..fbe0c9b 100644
--- a/src/keymap-dump.c
+++ b/src/keymap-dump.c
@@ -310,6 +310,7 @@ write_keycodes(struct xkb_keymap *keymap, char **buf, size_t *size,
                size_t *offset)
 {
     xkb_keycode_t kc;
+    struct xkb_key *key;
     struct xkb_key_alias *alias;
     int i;
 
@@ -325,12 +326,12 @@ write_keycodes(struct xkb_keymap *keymap, char **buf, size_t *size,
               keymap->max_key_code);
 
     for (kc = keymap->min_key_code; kc <= keymap->max_key_code; kc++) {
-        if (darray_item(keymap->key_names, kc).name[0] == '\0')
+        key = XkbKey(keymap, kc);
+        if (key->name.name[0] == '\0')
             continue;
 
         write_buf(keymap, buf, size, offset, "\t\t%6s = %d;\n",
-                  XkbcKeyNameText(darray_item(keymap->key_names, kc).name),
-                  kc);
+                  XkbcKeyNameText(key->name.name), kc);
     }
 
     for (i = 0; i < XkbNumIndicators; i++) {
@@ -780,6 +781,7 @@ static bool
 write_symbols(struct xkb_keymap *keymap, char **buf, size_t *size,
               size_t *offset)
 {
+    struct xkb_key *key;
     xkb_keycode_t kc;
     int group, tmp;
     bool showActions;
@@ -803,62 +805,63 @@ write_symbols(struct xkb_keymap *keymap, char **buf, size_t *size,
 
     for (kc = keymap->min_key_code; kc <= keymap->max_key_code; kc++) {
         bool simple = true;
+        key = XkbKey(keymap, kc);
 
         if (xkb_key_num_groups(keymap, kc) == 0)
             continue;
 
         write_buf(keymap, buf, size, offset, "\t\tkey %6s {",
-                  XkbcKeyNameText(darray_item(keymap->key_names, kc).name));
-        if (keymap->explicit) {
-            if ((keymap->explicit[kc] & XkbExplicitKeyTypesMask)) {
-                bool multi_type = false;
-                int type = XkbKeyTypeIndex(keymap, kc, 0);
+                  XkbcKeyNameText(key->name.name));
 
-                simple = false;
+        if (key->explicit & XkbExplicitKeyTypesMask) {
+            bool multi_type = false;
+            int type = XkbKeyTypeIndex(keymap, kc, 0);
 
-                for (group = 0; group < xkb_key_num_groups(keymap, kc);
-                     group++) {
-                    if (XkbKeyTypeIndex(keymap, kc, group) != type) {
-                        multi_type = true;
-                        break;
-                    }
-                }
-                if (multi_type) {
-                    for (group = 0;
-                         group < xkb_key_num_groups(keymap, kc);
-                         group++) {
-                        if (!(keymap->explicit[kc] & (1 << group)))
-                            continue;
-                        type = XkbKeyTypeIndex(keymap, kc, group);
-                        write_buf(keymap, buf, size, offset,
-                                  "\n\t\t\ttype[group%d]= \"%s\",",
-                                  group + 1,
-                                  darray_item(keymap->types, type).name);
-                    }
+            simple = false;
+
+            for (group = 0; group < xkb_key_num_groups(keymap, kc);
+                 group++) {
+                if (XkbKeyTypeIndex(keymap, kc, group) != type) {
+                    multi_type = true;
+                    break;
                 }
-                else {
+            }
+
+            if (multi_type) {
+                for (group = 0;
+                     group < xkb_key_num_groups(keymap, kc);
+                     group++) {
+                    if (!(key->explicit & (1 << group)))
+                        continue;
+                    type = XkbKeyTypeIndex(keymap, kc, group);
                     write_buf(keymap, buf, size, offset,
-                              "\n\t\t\ttype= \"%s\",",
+                              "\n\t\t\ttype[group%d]= \"%s\",",
+                              group + 1,
                               darray_item(keymap->types, type).name);
                 }
             }
-            if (keymap->explicit[kc] & XkbExplicitAutoRepeatMask) {
-                if (keymap->per_key_repeat[kc / 8] & (1 << (kc % 8)))
-                    write_buf(keymap, buf, size, offset,
-                              "\n\t\t\trepeat= Yes,");
-                else
-                    write_buf(keymap, buf, size, offset,
-                              "\n\t\t\trepeat= No,");
-                simple = false;
-            }
-            if (keymap->vmodmap[kc] &&
-                (keymap->explicit[kc] & XkbExplicitVModMapMask)) {
+            else {
                 write_buf(keymap, buf, size, offset,
-                          "\n\t\t\tvirtualMods= %s,",
-                          get_mod_mask_text(keymap, 0, keymap->vmodmap[kc]));
+                          "\n\t\t\ttype= \"%s\",",
+                          darray_item(keymap->types, type).name);
             }
         }
 
+        if (key->explicit & XkbExplicitAutoRepeatMask) {
+            if (key->repeats)
+                write_buf(keymap, buf, size, offset,
+                          "\n\t\t\trepeat= Yes,");
+            else
+                write_buf(keymap, buf, size, offset,
+                          "\n\t\t\trepeat= No,");
+            simple = false;
+        }
+
+        if (key->vmodmap && (key->explicit & XkbExplicitVModMapMask)) {
+            write_buf(keymap, buf, size, offset, "\n\t\t\tvirtualMods= %s,",
+                      get_mod_mask_text(keymap, 0, key->vmodmap));
+        }
+
         switch (XkbOutOfRangeGroupAction(XkbKeyGroupInfo(keymap, kc))) {
         case XkbClampIntoRange:
             write_buf(keymap, buf, size, offset, "\n\t\t\tgroupsClamp,");
@@ -872,8 +875,7 @@ write_symbols(struct xkb_keymap *keymap, char **buf, size_t *size,
             break;
         }
 
-        if (keymap->explicit == NULL ||
-            (keymap->explicit[kc] & XkbExplicitInterpretMask))
+        if (key->explicit & XkbExplicitInterpretMask)
             showActions = XkbKeyHasActions(keymap, kc);
         else
             showActions = false;
@@ -918,23 +920,22 @@ write_symbols(struct xkb_keymap *keymap, char **buf, size_t *size,
             write_buf(keymap, buf, size, offset, "\n\t\t};\n");
         }
     }
-    if (keymap->modmap) {
-        for (kc = keymap->min_key_code; kc <= keymap->max_key_code; kc++) {
-            int mod;
 
-            if (keymap->modmap[kc] == 0)
-                continue;
+    for (kc = keymap->min_key_code; kc <= keymap->max_key_code; kc++) {
+        int mod;
+        key = XkbKey(keymap, kc);
 
-            for (mod = 0; mod < XkbNumModifiers; mod++) {
-                if (!(keymap->modmap[kc] & (1 << mod)))
-                    continue;
+        if (key->modmap == 0)
+            continue;
 
-                write_buf(keymap, buf, size, offset,
-                          "\t\tmodifier_map %s { %s };\n",
-                          get_mod_index_text(mod),
-                          XkbcKeyNameText(darray_item(keymap->key_names,
-                                                      kc).name));
-            }
+        for (mod = 0; mod < XkbNumModifiers; mod++) {
+            if (!(key->modmap & (1 << mod)))
+                continue;
+
+            write_buf(keymap, buf, size, offset,
+                      "\t\tmodifier_map %s { %s };\n",
+                      get_mod_index_text(mod),
+                      XkbcKeyNameText(key->name.name));
         }
     }
 
diff --git a/src/map.c b/src/map.c
index 431019c..91b2a65 100644
--- a/src/map.c
+++ b/src/map.c
@@ -357,5 +357,7 @@ err:
 _X_EXPORT int
 xkb_key_repeats(struct xkb_keymap *keymap, xkb_keycode_t kc)
 {
-    return !!(keymap->per_key_repeat[kc / 8] & (1 << (kc % 8)));
+    if (!XkbKeycodeInRange(keymap, kc))
+        return 0;
+    return XkbKey(keymap, kc)->repeats;
 }
diff --git a/src/xkb-priv.h b/src/xkb-priv.h
index 0890290..3c0ecab 100644
--- a/src/xkb-priv.h
+++ b/src/xkb-priv.h
@@ -309,6 +309,18 @@ struct xkb_controls {
     unsigned int axt_ctrls_values;
 };
 
+struct xkb_key {
+    struct xkb_key_name name;
+    unsigned char explicit;
+    struct xkb_sym_map sym_map;
+    unsigned char modmap;
+    uint32_t vmodmap;
+    struct xkb_behavior behavior;
+    bool repeats;
+    /* Index into keymap->acts */
+    size_t acts_index;
+};
+
 /* Common keyboard description structure */
 struct xkb_keymap {
     struct xkb_context *ctx;
@@ -321,25 +333,15 @@ struct xkb_keymap {
     xkb_keycode_t min_key_code;
     xkb_keycode_t max_key_code;
 
-    /* key -> key name mapping */
-    darray(struct xkb_key_name) key_names;
+    darray(struct xkb_key) keys;
+
     /* aliases in no particular order */
     darray(struct xkb_key_alias) key_aliases;
 
-    /* key -> explicit flags mapping */
-    unsigned char *explicit;
-
     darray(struct xkb_key_type) types;
 
-    /* key -> symbols mapping */
-    darray(struct xkb_sym_map) key_sym_map;
-
     darray(struct xkb_sym_interpret) sym_interpret;
 
-    /* key -> mod mapping */
-    unsigned char *modmap;
-    /* key -> vmod mapping */
-    uint32_t *vmodmap;
     /* vmod -> mod mapping */
     uint32_t vmods[XkbNumVirtualMods];
     char *vmod_names[XkbNumVirtualMods];
@@ -347,15 +349,7 @@ struct xkb_keymap {
     struct xkb_mods groups[XkbNumKbdGroups];
     char *group_names[XkbNumKbdGroups];
 
-    /* key -> actions mapping: acts[key_acts[keycode]] */
     darray(union xkb_action) acts;
-    darray(size_t) key_acts;
-
-    /* key -> behavior mapping */
-    struct xkb_behavior *behaviors;
-
-    /* key -> should repeat mapping - one bit per key */
-    unsigned char *per_key_repeat;
 
     struct xkb_indicator_map indicators[XkbNumIndicators];
     char *indicator_names[XkbNumIndicators];
@@ -366,6 +360,12 @@ struct xkb_keymap {
     char *compat_section_name;
 };
 
+static inline struct xkb_key *
+XkbKey(struct xkb_keymap *keymap, xkb_keycode_t kc)
+{
+    return &darray_item(keymap->keys, kc);
+}
+
 static inline unsigned char
 XkbNumGroups(unsigned char group_info)
 {
@@ -410,7 +410,7 @@ XkbSetNumGroups(unsigned char group_info, unsigned char num_groups)
 static inline unsigned char
 XkbKeyGroupInfo(struct xkb_keymap *keymap, xkb_keycode_t kc)
 {
-    return darray_item(keymap->key_sym_map, kc).group_info;
+    return XkbKey(keymap, kc)->sym_map.group_info;
 }
 
 static inline unsigned char
@@ -423,7 +423,7 @@ static inline unsigned char
 XkbKeyTypeIndex(struct xkb_keymap *keymap, xkb_keycode_t kc,
                 unsigned int group)
 {
-    return darray_item(keymap->key_sym_map, kc).kt_index[group & 0x3];
+    return XkbKey(keymap, kc)->sym_map.kt_index[group & 0x3];
 }
 
 static inline struct xkb_key_type *
@@ -442,7 +442,7 @@ XkbKeyGroupWidth(struct xkb_keymap *keymap, xkb_keycode_t kc,
 static inline unsigned char
 XkbKeyGroupsWidth(struct xkb_keymap *keymap, xkb_keycode_t kc)
 {
-    return darray_item(keymap->key_sym_map, kc).width;
+    return XkbKey(keymap, kc)->sym_map.width;
 }
 
 static inline unsigned int
@@ -450,14 +450,13 @@ XkbKeyNumSyms(struct xkb_keymap *keymap, xkb_keycode_t kc,
               unsigned int group, unsigned int level)
 {
     unsigned char width = XkbKeyGroupsWidth(keymap, kc);
-    return darray_item(keymap->key_sym_map,
-                       kc).num_syms[group * width + level];
+    return XkbKey(keymap, kc)->sym_map.num_syms[group * width + level];
 }
 
 static inline xkb_keysym_t *
 XkbKeySym(struct xkb_keymap *keymap, xkb_keycode_t kc, int ndx)
 {
-    return &darray_item(darray_item(keymap->key_sym_map, kc).syms, ndx);
+    return &darray_item(XkbKey(keymap, kc)->sym_map.syms, ndx);
 }
 
 static inline int
@@ -465,8 +464,7 @@ XkbKeySymOffset(struct xkb_keymap *keymap, xkb_keycode_t kc,
                 unsigned group, unsigned int level)
 {
     unsigned char width = XkbKeyGroupsWidth(keymap, kc);
-    return darray_item(keymap->key_sym_map,
-                       kc).sym_index[group * width + level];
+    return XkbKey(keymap, kc)->sym_map.sym_index[group * width + level];
 }
 
 static inline xkb_keysym_t *
@@ -479,7 +477,7 @@ XkbKeySymEntry(struct xkb_keymap *keymap, xkb_keycode_t kc,
 static inline bool
 XkbKeyHasActions(struct xkb_keymap *keymap, xkb_keycode_t kc)
 {
-    return darray_item(keymap->key_acts, kc) != 0;
+    return XkbKey(keymap, kc)->acts_index != 0;
 }
 
 static inline unsigned char
@@ -493,7 +491,8 @@ XkbKeyNumActions(struct xkb_keymap *keymap, xkb_keycode_t kc)
 static inline union xkb_action *
 XkbKeyActionsPtr(struct xkb_keymap *keymap, xkb_keycode_t kc)
 {
-    return darray_mem(keymap->acts, darray_item(keymap->key_acts, kc));
+    struct xkb_key *key = XkbKey(keymap, kc);
+    return darray_mem(keymap->acts, key->acts_index);
 }
 
 static inline union xkb_action *
diff --git a/src/xkbcomp/compat.c b/src/xkbcomp/compat.c
index 1ab6754..9c551c9 100644
--- a/src/xkbcomp/compat.c
+++ b/src/xkbcomp/compat.c
@@ -847,7 +847,7 @@ FindInterpForKey(struct xkb_keymap *keymap, xkb_keycode_t kc,
             continue;
 
         if (level == 0 || !(interp->match & XkbSI_LevelOneOnly))
-            mods = keymap->modmap[kc];
+            mods = XkbKey(keymap, kc)->modmap;
         else
             mods = 0;
 
@@ -893,10 +893,13 @@ ApplyInterpsToKey(struct xkb_keymap *keymap, xkb_keycode_t kc)
     int num_acts = 0;
     int group, level;
     int width = XkbKeyGroupsWidth(keymap, kc);
+    struct xkb_key *key;
     int i;
 
+    key = XkbKey(keymap, kc);
+
     /* If we've been told not to bind interps to this key, then don't. */
-    if (keymap->explicit[kc] & XkbExplicitInterpretMask)
+    if (key->explicit & XkbExplicitInterpretMask)
         return true;
 
     for (i = 0; i < INTERP_SIZE; i++)
@@ -930,12 +933,12 @@ ApplyInterpsToKey(struct xkb_keymap *keymap, xkb_keycode_t kc)
 
             /* Infer default key behaviours from the base level. */
             if (group == 0 && level == 0) {
-                if (!(keymap->explicit[kc] & XkbExplicitAutoRepeatMask) &&
+                if (!(key->explicit & XkbExplicitAutoRepeatMask) &&
                     (!interp || interp->flags & XkbSI_AutoRepeat))
-                    keymap->per_key_repeat[kc / 8] |= (1 << (kc % 8));
-                if (!(keymap->explicit[kc] & XkbExplicitBehaviorMask) &&
+                    key->repeats = true;
+                if (!(key->explicit & XkbExplicitBehaviorMask) &&
                     interp && (interp->flags & XkbSI_LockingKey))
-                    keymap->behaviors[kc].type = XkbKB_Lock;
+                    key->behavior.type = XkbKB_Lock;
             }
 
             if (!interp)
@@ -950,8 +953,8 @@ ApplyInterpsToKey(struct xkb_keymap *keymap, xkb_keycode_t kc)
         }
     }
 
-    if (!(keymap->explicit[kc] & XkbExplicitVModMapMask))
-        keymap->vmodmap[kc] = vmodmask;
+    if (!(key->explicit & XkbExplicitVModMapMask))
+        key->vmodmap = vmodmask;
 
     return true;
 #undef INTERP_SIZE
@@ -967,6 +970,7 @@ bool
 UpdateModifiersFromCompat(struct xkb_keymap *keymap)
 {
     xkb_keycode_t kc;
+    struct xkb_key *key;
     int i;
     struct xkb_key_type *type;
     struct xkb_kt_map_entry *entry;
@@ -981,12 +985,13 @@ UpdateModifiersFromCompat(struct xkb_keymap *keymap)
     for (i = 0; i < XkbNumVirtualMods; i++)
         keymap->vmods[i] = 0;
     for (kc = keymap->min_key_code; kc <= keymap->max_key_code; kc++) {
-        if (!keymap->vmodmap[kc])
+        key = XkbKey(keymap, kc);
+        if (!key->vmodmap)
             continue;
         for (i = 0; i < XkbNumVirtualMods; i++) {
-            if (!(keymap->vmodmap[kc] & (1 << i)))
+            if (!(key->vmodmap & (1 << i)))
                 continue;
-            keymap->vmods[i] |= keymap->modmap[kc];
+            keymap->vmods[i] |= key->modmap;
         }
     }
 
@@ -1010,10 +1015,11 @@ UpdateModifiersFromCompat(struct xkb_keymap *keymap)
     /* Update action modifiers. */
     for (kc = keymap->min_key_code; kc <= keymap->max_key_code; kc++) {
         union xkb_action *acts = XkbKeyActionsPtr(keymap, kc);
+        key = XkbKey(keymap, kc);
         for (i = 0; i < XkbKeyNumActions(keymap, kc); i++) {
             if (acts[i].any.type == XkbSA_NoAction)
                 continue;
-            UpdateActionMods(keymap, &acts[i], keymap->modmap[kc]);
+            UpdateActionMods(keymap, &acts[i], key->modmap);
         }
     }
 
diff --git a/src/xkbcomp/keycodes.c b/src/xkbcomp/keycodes.c
index 3fba2a5..9ff9f37 100644
--- a/src/xkbcomp/keycodes.c
+++ b/src/xkbcomp/keycodes.c
@@ -754,10 +754,10 @@ CompileKeycodes(XkbFile *file, struct xkb_keymap *keymap,
     else
         keymap->max_key_code = info.computedMax;
 
-    darray_resize0(keymap->key_names, keymap->max_key_code + 1);
+    darray_resize0(keymap->keys, keymap->max_key_code + 1);
     for (kc = info.computedMin; kc <= info.computedMax; kc++)
         LongToKeyName(darray_item(info.names, kc),
-                      darray_item(keymap->key_names, kc).name);
+                      XkbKey(keymap, kc)->name.name);
 
     if (info.name)
         keymap->keycodes_section_name = strdup(info.name);
diff --git a/src/xkbcomp/misc.c b/src/xkbcomp/misc.c
index 7692e8c..e10a23e 100644
--- a/src/xkbcomp/misc.c
+++ b/src/xkbcomp/misc.c
@@ -217,7 +217,8 @@ FindNamedKey(struct xkb_keymap *keymap, unsigned long name,
              xkb_keycode_t *kc_rtrn, bool use_aliases, bool create,
              xkb_keycode_t start_from)
 {
-    unsigned n;
+    xkb_keycode_t kc;
+    struct xkb_key *key;
 
     if (start_from < keymap->min_key_code)
         start_from = keymap->min_key_code;
@@ -226,34 +227,36 @@ FindNamedKey(struct xkb_keymap *keymap, unsigned long name,
 
     *kc_rtrn = 0;               /* some callers rely on this */
 
-    if (!darray_empty(keymap->key_names)) {
-        for (n = start_from; n <= keymap->max_key_code; n++) {
-            unsigned long tmp;
-            tmp = KeyNameToLong(darray_item(keymap->key_names, n).name);
-            if (tmp == name) {
-                *kc_rtrn = n;
-                return true;
-            }
-        }
-        if (use_aliases) {
-            unsigned long new_name;
-            if (FindKeyNameForAlias(keymap, name, &new_name))
-                return FindNamedKey(keymap, new_name, kc_rtrn, false,
-                                    create, 0);
+    for (kc = start_from; kc <= keymap->max_key_code; kc++) {
+        unsigned long tmp;
+        key = XkbKey(keymap, kc);
+
+        tmp = KeyNameToLong(key->name.name);
+        if (tmp == name) {
+            *kc_rtrn = kc;
+            return true;
         }
     }
 
+    if (use_aliases) {
+        unsigned long new_name;
+        if (FindKeyNameForAlias(keymap, name, &new_name))
+            return FindNamedKey(keymap, new_name, kc_rtrn, false,
+                                create, 0);
+    }
+
     if (create) {
-        darray_resize0(keymap->key_names, keymap->max_key_code + 1);
+        darray_resize0(keymap->keys, keymap->max_key_code + 1);
 
         /* Find first unused keycode and store our key here */
-        for (n = keymap->min_key_code; n <= keymap->max_key_code; n++) {
-            if (darray_item(keymap->key_names, n).name[0] == '\0') {
+        for (kc = keymap->min_key_code; kc <= keymap->max_key_code; kc++) {
+            key = XkbKey(keymap, kc);
+
+            if (key->name.name[0] == '\0') {
                 char buf[XkbKeyNameLength + 1];
                 LongToKeyName(name, buf);
-                memcpy(darray_item(keymap->key_names, n).name, buf,
-                       XkbKeyNameLength);
-                *kc_rtrn = n;
+                memcpy(key->name.name, buf, XkbKeyNameLength);
+                *kc_rtrn = kc;
                 return true;
             }
         }
diff --git a/src/xkbcomp/symbols.c b/src/xkbcomp/symbols.c
index c67bf1d..0adc819 100644
--- a/src/xkbcomp/symbols.c
+++ b/src/xkbcomp/symbols.c
@@ -1693,6 +1693,7 @@ CopySymbolsDef(struct xkb_keymap *keymap, KeyInfo *keyi, int start_from)
 {
     unsigned int i;
     xkb_keycode_t kc;
+    struct xkb_key *key;
     unsigned int sizeSyms = 0;
     unsigned width, tmp, nGroups;
     struct xkb_key_type * type;
@@ -1714,6 +1715,8 @@ CopySymbolsDef(struct xkb_keymap *keymap, KeyInfo *keyi, int start_from)
         return false;
     }
 
+    key = XkbKey(keymap, kc);
+
     haveActions = false;
     for (i = width = nGroups = 0; i < XkbNumKbdGroups; i++) {
         if (((i + 1) > nGroups)
@@ -1742,7 +1745,7 @@ CopySymbolsDef(struct xkb_keymap *keymap, KeyInfo *keyi, int start_from)
         }
         if (FindNamedType(keymap, keyi->types[i], &types[i])) {
             if (!autoType || keyi->numLevels[i] > 2)
-                keymap->explicit[kc] |= (1 << i);
+                key->explicit |= (1 << i);
         }
         else {
             if (warningLevel >= 3) {
@@ -1783,12 +1786,12 @@ CopySymbolsDef(struct xkb_keymap *keymap, KeyInfo *keyi, int start_from)
                  longText(keyi->name), kc);
             return false;
         }
-        keymap->explicit[kc] |= XkbExplicitInterpretMask;
+        key->explicit |= XkbExplicitInterpretMask;
     }
     else
         outActs = NULL;
 
-    sym_map = &darray_item(keymap->key_sym_map, kc);
+    sym_map = &key->sym_map;
 
     if (keyi->defs.defined & _Key_GroupInfo)
         i = keyi->groupInfo;
@@ -1843,20 +1846,17 @@ CopySymbolsDef(struct xkb_keymap *keymap, KeyInfo *keyi, int start_from)
         break;
 
     default:
-        keymap->behaviors[kc] = keyi->behavior;
-        keymap->explicit[kc] |= XkbExplicitBehaviorMask;
+        key->behavior = keyi->behavior;
+        key->explicit |= XkbExplicitBehaviorMask;
         break;
     }
     if (keyi->defs.defined & _Key_VModMap) {
-        keymap->vmodmap[kc] = keyi->vmodmap;
-        keymap->explicit[kc] |= XkbExplicitVModMapMask;
+        key->vmodmap = keyi->vmodmap;
+        key->explicit |= XkbExplicitVModMapMask;
     }
     if (keyi->repeat != RepeatUndefined) {
-        if (keyi->repeat == RepeatYes)
-            keymap->per_key_repeat[kc / 8] |= (1 << (kc % 8));
-        else
-            keymap->per_key_repeat[kc / 8] &= ~(1 << (kc % 8));
-        keymap->explicit[kc] |= XkbExplicitAutoRepeatMask;
+        key->repeats = keyi->repeat == RepeatYes;
+        key->explicit |= XkbExplicitAutoRepeatMask;
     }
 
     /* do the same thing for the next key */
@@ -1890,7 +1890,8 @@ CopyModMapDef(struct xkb_keymap *keymap, ModMapEntry *entry)
         }
         return false;
     }
-    keymap->modmap[kc] |= (1 << entry->modifier);
+
+    XkbKey(keymap, kc)->modmap |= (1 << entry->modifier);
     return true;
 }
 
@@ -1899,30 +1900,9 @@ InitKeymapForSymbols(struct xkb_keymap *keymap)
 {
     size_t nKeys = keymap->max_key_code + 1;
 
-    darray_resize0(keymap->key_sym_map, nKeys);
-
-    keymap->modmap = calloc(nKeys, sizeof(*keymap->modmap));
-    if (!keymap->modmap)
-        return false;
-
-    keymap->explicit = calloc(nKeys, sizeof(*keymap->explicit));
-    if (!keymap->explicit)
-        return false;
+    darray_resize0(keymap->keys, nKeys);
 
     darray_resize0(keymap->acts, darray_size(keymap->acts) + 32 + 1);
-    darray_resize0(keymap->key_acts, nKeys);
-
-    keymap->behaviors = calloc(nKeys, sizeof(*keymap->behaviors));
-    if (!keymap->behaviors)
-        return false;
-
-    keymap->vmodmap = calloc(nKeys, sizeof(*keymap->vmodmap));
-    if (!keymap->vmodmap)
-        return false;
-
-    keymap->per_key_repeat = calloc(nKeys / 8, 1);
-    if (!keymap->per_key_repeat)
-        return false;
 
     return true;
 }
@@ -1941,6 +1921,7 @@ CompileSymbols(XkbFile *file, struct xkb_keymap *keymap,
     int i;
     bool ok;
     xkb_keycode_t kc;
+    struct xkb_key *key;
     SymbolsInfo info;
     KeyInfo *keyi;
 
@@ -1984,15 +1965,13 @@ CompileSymbols(XkbFile *file, struct xkb_keymap *keymap,
 
     if (warningLevel > 3) {
         for (kc = keymap->min_key_code; kc <= keymap->max_key_code; kc++) {
-            if (darray_item(keymap->key_names, kc).name[0] == '\0')
+            key = XkbKey(keymap, kc);
+            if (key->name.name[0] == '\0')
                 continue;
 
-            if (XkbKeyNumGroups(keymap, kc) < 1) {
-                char buf[5];
-                memcpy(buf, darray_item(keymap->key_names, kc).name, 4);
-                buf[4] = '\0';
-                WARN("No symbols defined for <%s> (keycode %d)\n", buf, kc);
-            }
+            if (XkbKeyNumGroups(keymap, kc) < 1)
+                WARN("No symbols defined for <%.4s> (keycode %d)\n",
+                     key->name.name, kc);
         }
     }