mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-02-05 04:06:08 -05:00
url-mode: generate-key-combos: minor efficiency tweaks
* Use a do..while loop; this lets us drop the second half of the loop condition. * Call wcslen(prefix) once, *before* iterating the alphabet characters. * Step through the alphabet characters using a pointer, as this avoids an indexed load (with possibly an imul instruction in e.g. -Os builds).
This commit is contained in:
parent
c84e379767
commit
9ee392dc8c
1 changed files with 8 additions and 7 deletions
15
url-mode.c
15
url-mode.c
|
|
@ -365,22 +365,23 @@ generate_key_combos(size_t count, wchar_t *combos[static count])
|
|||
hints[0] = xwcsdup(L"");
|
||||
|
||||
size_t offset = 0;
|
||||
while (hints_count - offset < count || hints_count == 1) {
|
||||
do {
|
||||
const wchar_t *prefix = hints[offset++];
|
||||
const size_t prefix_len = wcslen(prefix);
|
||||
|
||||
hints = xrealloc(hints, (hints_count + alphabet_len) * sizeof(hints[0]));
|
||||
|
||||
for (size_t i = 0; i < alphabet_len; i++) {
|
||||
wchar_t wc = alphabet[i];
|
||||
wchar_t *hint = xmalloc((wcslen(prefix) + 1 + 1) * sizeof(wchar_t));
|
||||
const wchar_t *wc = &alphabet[0];
|
||||
for (size_t i = 0; i < alphabet_len; i++, wc++) {
|
||||
wchar_t *hint = xmalloc((prefix_len + 1 + 1) * sizeof(wchar_t));
|
||||
hints[hints_count + i] = hint;
|
||||
|
||||
/* Will be reversed later */
|
||||
hint[0] = wc;
|
||||
hint[0] = *wc;
|
||||
wcscpy(&hint[1], prefix);
|
||||
hints[hints_count + i] = hint;
|
||||
}
|
||||
hints_count += alphabet_len;
|
||||
}
|
||||
} while (hints_count - offset < count);
|
||||
|
||||
xassert(hints_count - offset >= count);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue