engine: look dictionaries up synchronously

The dictionary thread ran in imthread's own proc, so a lookup could
only start once the engine blocked, and it was a trie probe anyway; the
emoji and Hanja searches already called dictlookup directly. The
request/result channels, sequence numbers, staleness checks and the
second draw per Japanese key are gone; dictqjp fills the candidates
in place. Emit.dict and Lang.dictq only ever triggered lookups for
Vietnamese, which has no dictionary. dictlookup(Lang*, key, out, max)
returns the count. The Hanja lookup no longer pre-checks for a single
syllable; a reading either has an entry or it does not.
This commit is contained in:
2026-08-16 16:02:09 +09:00
parent ebcec3af6b
commit abaea77248
10 changed files with 123 additions and 473 deletions

50
dict.c
View File

@@ -1,52 +1,34 @@
#include "dat.h"
#include "fn.h"
/* Candidates are the space-separated words of the value; the reading itself
* is a candidate only for the emoji dictionary. */
void
dictlookup(Dictreq *req, Dictres *res)
/*
* Fills out[] with up to max candidates for key: the space-separated words
* of the entry, minus the key itself except in the emoji dictionary, where
* a query may name its own answer.
*/
int
dictlookup(Lang *l, Str *key, Str *out, int max)
{
Lang *l;
char *p, *e, *sp;
Str tmp;
int vlen;
int n, vlen;
res->key = req->pre;
res->nkouho = 0;
res->lang = req->lang;
res->seq = req->seq;
l = getlang(req->lang);
if(req->key.n == 0 || l == nil ||
trielookup(l->dict, &req->key, &p, &vlen) != TrieExact)
return;
if(l == nil || key->n == 0 ||
trielookup(l->dict, key, &p, &vlen) != TrieExact)
return 0;
n = 0;
e = p + vlen;
while(res->nkouho < Maxkouho && p < e){
while(n < max && p < e){
while(p < e && *p == ' ')
p++;
sp = p;
while(p < e && *p != ' ')
p++;
if(sinit(&tmp, sp, p - sp) && tmp.n > 0 &&
(req->lang == LangEMOJI || scmp(&tmp, &req->key) != 0))
res->kouho[res->nkouho++] = tmp;
}
}
void
dictthread(void*)
{
Dictreq req;
static Dictres res;
threadsetname("dict");
for(;;){
if(chanrecv(dictreqc, &req) < 0)
break;
while(channbrecv(dictreqc, &req) > 0)
;
dictlookup(&req, &res);
chansend(dictresc, &res);
(l->lang == LangEMOJI || scmp(&tmp, key) != 0))
out[n++] = tmp;
}
return n;
}
static Trie*