From 994c1c7ae6950b30a60f7c48eb2cbcc72b427620 Mon Sep 17 00:00:00 2001 From: Jeff Doozan Date: Mon, 21 Dec 2020 17:10:02 -0500 Subject: [PATCH] Use mapfile directly instead of buffer --- src/stardict_lib.cpp | 9 ++------- src/stardict_lib.hpp | 9 +++------ 2 files changed, 5 insertions(+), 13 deletions(-) diff --git a/src/stardict_lib.cpp b/src/stardict_lib.cpp index 8ae6c88..6b1f92b 100644 --- a/src/stardict_lib.cpp +++ b/src/stardict_lib.cpp @@ -831,19 +831,14 @@ bool WordListIndex::lookup(const char *str, glong &idx) bool SynFile::load(const std::string &url, gulong wc) { - struct stat stat_buf; if (!stat(url.c_str(), &stat_buf)) { - MapFile syn; - if (!syn.open(url.c_str(), stat_buf.st_size)) + if (!synfile.open(url.c_str(), stat_buf.st_size)) return false; - syndatabuf = (gchar *)g_malloc(stat_buf.st_size); - memcpy(syndatabuf, syn.begin(), stat_buf.st_size); - synlist.resize(wc + 1); - gchar *p1 = syndatabuf; + gchar *p1 = synfile.begin(); for (unsigned long i = 0; i < wc; i++) { // each entry in a syn-file is: diff --git a/src/stardict_lib.hpp b/src/stardict_lib.hpp index c3c346d..38f76f4 100644 --- a/src/stardict_lib.hpp +++ b/src/stardict_lib.hpp @@ -102,17 +102,14 @@ public: class SynFile { public: - SynFile() - : syndatabuf(nullptr) - { - } - ~SynFile() { g_free(syndatabuf); } + SynFile() {} + ~SynFile() {} bool load(const std::string &url, gulong wc); bool lookup(const char *str, glong &idx); const gchar *get_key(glong idx) { return synlist[idx]; } private: - gchar *syndatabuf; + MapFile synfile; std::vector synlist; };