Synonyms: Use MapFile

This commit is contained in:
Jeff Doozan
2020-12-21 08:53:29 -05:00
parent cc7bcb8b73
commit d38f8f13c9

View File

@@ -831,25 +831,16 @@ bool WordListIndex::lookup(const char *str, glong &idx)
bool SynFile::load(const std::string &url, gulong wc) bool SynFile::load(const std::string &url, gulong wc)
{ {
struct stat stat_buf; struct stat stat_buf;
if (!stat(url.c_str(), &stat_buf)) { if (!stat(url.c_str(), &stat_buf)) {
FILE *in = fopen(url.c_str(), "rb"); MapFile syn;
if (!in) if (!syn.open(url.c_str(), stat_buf.st_size))
return false; return false;
fseek(in, 0, SEEK_END); syndatabuf = (gchar *)g_malloc(stat_buf.st_size);
gulong fsize = ftell(in); memcpy(syndatabuf, syn.begin(), stat_buf.st_size);
fseek(in, 0, SEEK_SET);
syndatabuf = (gchar *)g_malloc(fsize);
const int len = fread(syndatabuf, 1, fsize, in);
fclose(in);
if (len < 0)
return false;
if (gulong(len) != fsize)
return false;
synlist.resize(wc + 1); synlist.resize(wc + 1);
gchar *p1 = syndatabuf; gchar *p1 = syndatabuf;