mirror of
https://github.com/Dushistov/sdcv.git
synced 2025-12-15 17:31:56 +00:00
Use mapfile directly instead of buffer
This commit is contained in:
@@ -831,19 +831,14 @@ 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)) {
|
||||||
|
|
||||||
MapFile syn;
|
if (!synfile.open(url.c_str(), stat_buf.st_size))
|
||||||
if (!syn.open(url.c_str(), stat_buf.st_size))
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
syndatabuf = (gchar *)g_malloc(stat_buf.st_size);
|
|
||||||
memcpy(syndatabuf, syn.begin(), stat_buf.st_size);
|
|
||||||
|
|
||||||
synlist.resize(wc + 1);
|
synlist.resize(wc + 1);
|
||||||
gchar *p1 = syndatabuf;
|
gchar *p1 = synfile.begin();
|
||||||
|
|
||||||
for (unsigned long i = 0; i < wc; i++) {
|
for (unsigned long i = 0; i < wc; i++) {
|
||||||
// each entry in a syn-file is:
|
// each entry in a syn-file is:
|
||||||
|
|||||||
@@ -102,17 +102,14 @@ public:
|
|||||||
class SynFile
|
class SynFile
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
SynFile()
|
SynFile() {}
|
||||||
: syndatabuf(nullptr)
|
~SynFile() {}
|
||||||
{
|
|
||||||
}
|
|
||||||
~SynFile() { g_free(syndatabuf); }
|
|
||||||
bool load(const std::string &url, gulong wc);
|
bool load(const std::string &url, gulong wc);
|
||||||
bool lookup(const char *str, glong &idx);
|
bool lookup(const char *str, glong &idx);
|
||||||
const gchar *get_key(glong idx) { return synlist[idx]; }
|
const gchar *get_key(glong idx) { return synlist[idx]; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
gchar *syndatabuf;
|
MapFile synfile;
|
||||||
std::vector<gchar *> synlist;
|
std::vector<gchar *> synlist;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user