The hash map served a single exact-match lookup that the trie already answers, at the price of a second container, a second file loader with its own drift, and a Str-to-UTF-8 conversion on every chain probe. The files are small (kanji.dict is 7.5k lines), so the trie holds both. trieopen validates keys and each space-separated value word against Str and reports path:line; trielookup takes the Str every caller holds and treats a nil trie as an unloaded map; trienew/trieput exist for tests. The overflow guards on growth, Trie.root (always 0) and the per-language init loop written twice are gone.
72 lines
1.1 KiB
C
72 lines
1.1 KiB
C
#include "dat.h"
|
|
#include "fn.h"
|
|
|
|
Channel *drawc;
|
|
Channel *keyc;
|
|
Channel *dictreqc;
|
|
Channel *dictresc;
|
|
|
|
void
|
|
usage(void)
|
|
{
|
|
fprint(2, "usage: strans mapdir\n");
|
|
threadexitsall("usage");
|
|
}
|
|
|
|
void
|
|
die(char *fmt, ...)
|
|
{
|
|
va_list ap;
|
|
|
|
fprint(2, "strans: ");
|
|
va_start(ap, fmt);
|
|
vfprint(2, fmt, ap);
|
|
va_end(ap);
|
|
fprint(2, "\n");
|
|
threadexitsall("die");
|
|
}
|
|
|
|
void*
|
|
emalloc(ulong n)
|
|
{
|
|
void *p;
|
|
|
|
p = mallocz(n, 1);
|
|
if(p == nil)
|
|
die("out of memory");
|
|
return p;
|
|
}
|
|
|
|
void*
|
|
erealloc(void *p, ulong n)
|
|
{
|
|
p = realloc(p, n);
|
|
if(p == nil)
|
|
die("out of memory");
|
|
return p;
|
|
}
|
|
|
|
void
|
|
threadmain(int argc, char **argv)
|
|
{
|
|
char *display;
|
|
|
|
if(argc != 2)
|
|
usage();
|
|
|
|
drawc = chancreate(sizeof(Drawcmd), 4);
|
|
keyc = chancreate(sizeof(Keyreq), 0);
|
|
dictreqc = chancreate(sizeof(Dictreq), 4);
|
|
dictresc = chancreate(sizeof(Dictres), 0);
|
|
langinit(argv[1]);
|
|
srvinit();
|
|
proccreate(drawthread, nil, 16384);
|
|
proccreate(srvthread, nil, 16384);
|
|
proccreate(ibusthread, nil, 32768);
|
|
display = getenv("DISPLAY");
|
|
if(display != nil && display[0] != '\0')
|
|
proccreate(ximthread, nil, 32768);
|
|
threadcreate(dictthread, nil, 16384);
|
|
imthread(nil);
|
|
}
|