compat: use darray instead of list for interps

No need for a list here.

Signed-off-by: Ran Benita <ran234@gmail.com>
master
Ran Benita 2012-08-27 22:06:50 +03:00
parent 8c6694fd58
commit c9466b32df
1 changed files with 9 additions and 41 deletions

View File

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