symbols: use darray for KeyInfo 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
diff --git a/src/xkbcomp/symbols.c b/src/xkbcomp/symbols.c
index 58565c1..9ebbf92 100644
--- a/src/xkbcomp/symbols.c
+++ b/src/xkbcomp/symbols.c
@@ -256,8 +256,8 @@ typedef struct _ModMapEntry
} u;
} ModMapEntry;
-#define SYMBOLS_INIT_SIZE 110
-#define SYMBOLS_CHUNK 20
+#define SYMBOLS_INIT_SIZE 110
+
typedef struct _SymbolsInfo
{
char *name; /* e.g. pc+us+inet(evdev) */
@@ -266,9 +266,7 @@ typedef struct _SymbolsInfo
unsigned merge;
unsigned explicit_group;
unsigned groupInfo;
- unsigned szKeys;
- unsigned nKeys;
- KeyInfo *keys;
+ darray(KeyInfo) keys;
KeyInfo dflt;
VModInfo vmods;
ActionInfo *action;
@@ -289,9 +287,8 @@ InitSymbolsInfo(SymbolsInfo * info, struct xkb_keymap *keymap)
info->fileID = 0;
info->merge = MergeOverride;
info->groupInfo = 0;
- info->szKeys = SYMBOLS_INIT_SIZE;
- info->nKeys = 0;
- info->keys = uTypedCalloc(SYMBOLS_INIT_SIZE, KeyInfo);
+ darray_init(info->keys);
+ darray_growalloc(info->keys, SYMBOLS_INIT_SIZE);
info->modMap = NULL;
for (i = 0; i < XkbNumKbdGroups; i++)
info->groupNames[i] = XKB_ATOM_NONE;
@@ -304,15 +301,12 @@ InitSymbolsInfo(SymbolsInfo * info, struct xkb_keymap *keymap)
static void
FreeSymbolsInfo(SymbolsInfo * info)
{
- unsigned int i;
+ KeyInfo *key;
free(info->name);
- if (info->keys)
- {
- for (i = 0; i < info->nKeys; i++)
- FreeKeyInfo(&info->keys[i]);
- free(info->keys);
- }
+ darray_foreach(key, info->keys)
+ FreeKeyInfo(key);
+ darray_free(info->keys);
if (info->modMap)
ClearCommonInfo(&info->modMap->defs);
if (info->aliases)
@@ -710,35 +704,21 @@ MergeKeys(SymbolsInfo *info, struct xkb_keymap *keymap,
static bool
AddKeySymbols(SymbolsInfo *info, KeyInfo *key, struct xkb_keymap *keymap)
{
- unsigned int i;
unsigned long real_name;
+ KeyInfo *iter, *new;
+
+ darray_foreach(iter, info->keys)
+ if (iter->name == key->name)
+ return MergeKeys(info, keymap, iter, key);
- for (i = 0; i < info->nKeys; i++)
- {
- if (info->keys[i].name == key->name)
- return MergeKeys(info, keymap, &info->keys[i], key);
- }
if (FindKeyNameForAlias(keymap, key->name, &real_name))
- {
- for (i = 0; i < info->nKeys; i++)
- {
- if (info->keys[i].name == real_name)
- return MergeKeys(info, keymap, &info->keys[i], key);
- }
- }
- if (info->nKeys >= info->szKeys)
- {
- info->szKeys += SYMBOLS_CHUNK;
- info->keys =
- uTypedRecalloc(info->keys, info->nKeys, info->szKeys, KeyInfo);
- if (!info->keys)
- {
- WSGO("Could not allocate key symbols descriptions\n");
- ACTION("Some key symbols definitions may be lost\n");
- return false;
- }
- }
- return CopyKeyInfo(key, &info->keys[info->nKeys++], true);
+ darray_foreach(iter, info->keys)
+ if (iter->name == real_name)
+ return MergeKeys(info, keymap, iter, key);
+
+ darray_resize0(info->keys, darray_size(info->keys) + 1);
+ new = &darray_item(info->keys, darray_size(info->keys) - 1);
+ return CopyKeyInfo(key, new, true);
}
static bool
@@ -844,13 +824,15 @@ MergeIncludedSymbols(SymbolsInfo *into, SymbolsInfo *from,
into->groupNames[i] = from->groupNames[i];
}
}
- for (i = 0, key = from->keys; i < from->nKeys; i++, key++)
- {
+
+ darray_foreach(key, from->keys) {
if (merge != MergeDefault)
key->defs.merge = merge;
+
if (!AddKeySymbols(into, key, keymap))
into->errorCount++;
}
+
if (from->modMap != NULL)
{
ModMapEntry *mm, *next;
@@ -2188,7 +2170,7 @@ CompileSymbols(XkbFile *file, struct xkb_keymap *keymap, unsigned merge)
HandleSymbolsFile(file, keymap, merge, &info);
- if (info.nKeys == 0)
+ if (darray_empty(info.keys))
goto err_info;
if (info.errorCount != 0)
@@ -2232,11 +2214,11 @@ CompileSymbols(XkbFile *file, struct xkb_keymap *keymap, unsigned merge)
}
/* sanitize keys */
- for (key = info.keys, i = 0; i < info.nKeys; i++, key++)
+ darray_foreach(key, info.keys)
PrepareKeyDef(key);
/* copy! */
- for (key = info.keys, i = 0; i < info.nKeys; i++, key++)
+ darray_foreach(key, info.keys)
if (!CopySymbolsDef(keymap, key, 0))
info.errorCount++;