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:
50
dict.c
50
dict.c
@@ -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*
|
||||
|
||||
Reference in New Issue
Block a user