compat: use darray instead of list for interps No need for a list here. 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
diff --git a/src/xkbcomp/compat.c b/src/xkbcomp/compat.c
index c19de03..a83b6c2 100644
--- a/src/xkbcomp/compat.c
+++ b/src/xkbcomp/compat.c
@@ -146,7 +146,6 @@ typedef struct _SymInterpInfo {
enum si_field defined;
unsigned file_id;
enum merge_mode merge;
- struct list entry;
struct xkb_sym_interpret interp;
} SymInterpInfo;
@@ -174,9 +173,8 @@ typedef struct _CompatInfo {
char *name;
unsigned file_id;
int errorCount;
- int nInterps;
- struct list interps;
SymInterpInfo dflt;
+ darray(SymInterpInfo) interps;
LEDInfo ledDflt;
darray(LEDInfo) leds;
VModInfo vmods;
@@ -248,8 +246,7 @@ InitCompatInfo(CompatInfo *info, struct xkb_keymap *keymap, unsigned file_id)
info->name = NULL;
info->file_id = file_id;
info->errorCount = 0;
- info->nInterps = 0;
- list_init(&info->interps);
+ darray_init(info->interps);
info->act = NULL;
info->dflt.file_id = file_id;
info->dflt.defined = 0;
@@ -269,7 +266,6 @@ InitCompatInfo(CompatInfo *info, struct xkb_keymap *keymap, unsigned file_id)
static void
ClearCompatInfo(CompatInfo *info)
{
- SymInterpInfo *si, *next_si;
struct xkb_keymap *keymap = info->keymap;
free(info->name);
@@ -281,9 +277,7 @@ ClearCompatInfo(CompatInfo *info)
memset(&info->dflt.interp.act, 0, sizeof(info->dflt.interp.act));
info->dflt.interp.act.type = XkbSA_NoAction;
ClearIndicatorMapInfo(keymap->ctx, &info->ledDflt);
- info->nInterps = 0;
- list_foreach_safe(si, next_si, &info->interps, entry)
- free(si);
+ darray_free(info->interps);
darray_free(info->leds);
FreeActionInfo(info->act);
info->act = NULL;
@@ -292,26 +286,11 @@ ClearCompatInfo(CompatInfo *info)
}
static SymInterpInfo *
-NextInterp(CompatInfo *info)
-{
- SymInterpInfo *si;
-
- si = calloc(1, sizeof(*si));
- if (!si)
- return NULL;
-
- list_append(&si->entry, &info->interps);
- info->nInterps++;
-
- return si;
-}
-
-static SymInterpInfo *
FindMatchingInterp(CompatInfo *info, SymInterpInfo *new)
{
SymInterpInfo *old;
- list_foreach(old, &info->interps, entry)
+ darray_foreach(old, info->interps)
if (old->interp.sym == new->interp.sym &&
old->interp.mods == new->interp.mods &&
old->interp.match == new->interp.match)
@@ -343,14 +322,12 @@ AddInterp(CompatInfo *info, SymInterpInfo *new)
{
enum si_field collide;
SymInterpInfo *old;
- struct list entry;
int verbosity = xkb_get_log_verbosity(info->keymap->ctx);
collide = 0;
old = FindMatchingInterp(info, new);
if (old != NULL) {
if (new->merge == MERGE_REPLACE) {
- entry = old->entry;
if ((old->file_id == new->file_id && verbosity > 0) ||
verbosity > 9)
log_warn(info->keymap->ctx,
@@ -358,7 +335,6 @@ AddInterp(CompatInfo *info, SymInterpInfo *new)
"Earlier interpretation ignored\n",
siText(new, info));
*old = *new;
- old->entry = entry;
return true;
}
@@ -396,13 +372,7 @@ AddInterp(CompatInfo *info, SymInterpInfo *new)
return true;
}
- old = new;
- new = NextInterp(info);
- if (!new)
- return false;
- entry = new->entry;
- *new = *old;
- new->entry = entry;
+ darray_append(info->interps, *new);
return true;
}
@@ -543,7 +513,7 @@ static void
MergeIncludedCompatMaps(CompatInfo *into, CompatInfo *from,
enum merge_mode merge)
{
- SymInterpInfo *si, *next_si;
+ SymInterpInfo *si;
LEDInfo *led;
if (from->errorCount > 0) {
@@ -556,7 +526,7 @@ MergeIncludedCompatMaps(CompatInfo *into, CompatInfo *from,
from->name = NULL;
}
- list_foreach_safe(si, next_si, &from->interps, entry) {
+ darray_foreach(si, from->interps) {
si->merge = (merge == MERGE_DEFAULT ? si->merge : merge);
if (!AddInterp(into, si))
into->errorCount++;
@@ -1021,7 +991,7 @@ CopyInterps(CompatInfo *info, bool needSymbol, unsigned pred)
{
SymInterpInfo *si;
- list_foreach(si, &info->interps, entry) {
+ darray_foreach(si, info->interps) {
if (((si->interp.match & XkbSI_OpMask) != pred) ||
(needSymbol && si->interp.sym == XKB_KEY_NoSymbol) ||
(!needSymbol && si->interp.sym != XKB_KEY_NoSymbol))
@@ -1113,9 +1083,7 @@ CompileCompatMap(XkbFile *file, struct xkb_keymap *keymap,
if (info.name)
keymap->compat_section_name = strdup(info.name);
- darray_init(keymap->sym_interpret);
- if (info.nInterps > 0) {
- darray_growalloc(keymap->sym_interpret, info.nInterps);
+ if (!darray_empty(info.interps)) {
CopyInterps(&info, true, XkbSI_Exactly);
CopyInterps(&info, true, XkbSI_AllOf | XkbSI_NoneOf);
CopyInterps(&info, true, XkbSI_AnyOf);