Track some more memory
This commit is contained in:
parent
9adb97ea28
commit
dedb16bc73
|
@ -29,6 +29,7 @@
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <malloc.h>
|
||||||
|
|
||||||
namespace Kakoune
|
namespace Kakoune
|
||||||
{
|
{
|
||||||
|
@ -832,6 +833,7 @@ const CommandDesc debug_cmd = {
|
||||||
write_debug("BufferMeta: " + to_string(UsedMemory<MemoryDomain::BufferMeta>::byte_count));
|
write_debug("BufferMeta: " + to_string(UsedMemory<MemoryDomain::BufferMeta>::byte_count));
|
||||||
write_debug("WordDB: " + to_string(UsedMemory<MemoryDomain::WordDB>::byte_count));
|
write_debug("WordDB: " + to_string(UsedMemory<MemoryDomain::WordDB>::byte_count));
|
||||||
write_debug("Undefined: " + to_string(UsedMemory<MemoryDomain::Undefined>::byte_count));
|
write_debug("Undefined: " + to_string(UsedMemory<MemoryDomain::Undefined>::byte_count));
|
||||||
|
write_debug("Malloced: " + to_string(mallinfo().uordblks));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
throw runtime_error("unknown debug command '" + parser[0] + "'");
|
throw runtime_error("unknown debug command '" + parser[0] + "'");
|
||||||
|
|
|
@ -20,7 +20,7 @@ private:
|
||||||
void acquire(size_t slot);
|
void acquire(size_t slot);
|
||||||
void release(size_t slot) noexcept;
|
void release(size_t slot) noexcept;
|
||||||
|
|
||||||
UnorderedMap<StringView, size_t> m_slot_map;
|
UnorderedMap<StringView, size_t, MemoryDomain::InternedString> m_slot_map;
|
||||||
Vector<size_t, MemoryDomain::InternedString> m_free_slots;
|
Vector<size_t, MemoryDomain::InternedString> m_free_slots;
|
||||||
struct DataAndRefCount
|
struct DataAndRefCount
|
||||||
{
|
{
|
||||||
|
|
|
@ -82,17 +82,17 @@ void test_word_db()
|
||||||
WordDB word_db(buffer);
|
WordDB word_db(buffer);
|
||||||
auto res = word_db.find_matching("", prefix_match);
|
auto res = word_db.find_matching("", prefix_match);
|
||||||
std::sort(res.begin(), res.end());
|
std::sort(res.begin(), res.end());
|
||||||
kak_assert(res == std::vector<InternedString>{ "allo" COMMA "kanaky" COMMA "mutch" COMMA "tchaa" COMMA "tchou" });
|
kak_assert(res == WordDB::WordList{ "allo" COMMA "kanaky" COMMA "mutch" COMMA "tchaa" COMMA "tchou" });
|
||||||
kak_assert(word_db.get_word_occurences("tchou") == 3);
|
kak_assert(word_db.get_word_occurences("tchou") == 3);
|
||||||
kak_assert(word_db.get_word_occurences("allo") == 1);
|
kak_assert(word_db.get_word_occurences("allo") == 1);
|
||||||
buffer.erase(buffer.iterator_at({1, 6}), buffer.iterator_at({4, 0}));
|
buffer.erase(buffer.iterator_at({1, 6}), buffer.iterator_at({4, 0}));
|
||||||
res = word_db.find_matching("", prefix_match);
|
res = word_db.find_matching("", prefix_match);
|
||||||
std::sort(res.begin(), res.end());
|
std::sort(res.begin(), res.end());
|
||||||
kak_assert(res == std::vector<InternedString>{ "allo" COMMA "mutch" COMMA "tchou" });
|
kak_assert(res == WordDB::WordList{ "allo" COMMA "mutch" COMMA "tchou" });
|
||||||
buffer.insert(buffer.iterator_at({1, 0}), "re");
|
buffer.insert(buffer.iterator_at({1, 0}), "re");
|
||||||
res = word_db.find_matching("", subsequence_match);
|
res = word_db.find_matching("", subsequence_match);
|
||||||
std::sort(res.begin(), res.end());
|
std::sort(res.begin(), res.end());
|
||||||
kak_assert(res == std::vector<InternedString>{ "allo" COMMA "mutch" COMMA "retchou" COMMA "tchou" });
|
kak_assert(res == WordDB::WordList{ "allo" COMMA "mutch" COMMA "retchou" COMMA "tchou" });
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_utf8()
|
void test_utf8()
|
||||||
|
|
|
@ -28,7 +28,7 @@ UsedLetters used_letters(StringView str)
|
||||||
|
|
||||||
static WordDB::WordList get_words(const InternedString& content)
|
static WordDB::WordList get_words(const InternedString& content)
|
||||||
{
|
{
|
||||||
std::vector<InternedString> res;
|
WordDB::WordList res;
|
||||||
using Iterator = utf8::iterator<const char*, utf8::InvalidPolicy::Pass>;
|
using Iterator = utf8::iterator<const char*, utf8::InvalidPolicy::Pass>;
|
||||||
const char* word_start = content.begin();
|
const char* word_start = content.begin();
|
||||||
bool in_word = false;
|
bool in_word = false;
|
||||||
|
|
|
@ -22,13 +22,13 @@ public:
|
||||||
WordDB(const WordDB&) = delete;
|
WordDB(const WordDB&) = delete;
|
||||||
WordDB(WordDB&&) = default;
|
WordDB(WordDB&&) = default;
|
||||||
|
|
||||||
using WordList = std::vector<InternedString>;
|
using WordList = Vector<InternedString, MemoryDomain::WordDB>;
|
||||||
template<typename MatchFunc>
|
template<typename MatchFunc>
|
||||||
WordList find_matching(StringView str, MatchFunc match)
|
WordList find_matching(StringView str, MatchFunc match)
|
||||||
{
|
{
|
||||||
update_db();
|
update_db();
|
||||||
const UsedLetters letters = used_letters(str);
|
const UsedLetters letters = used_letters(str);
|
||||||
std::vector<InternedString> res;
|
WordList res;
|
||||||
for (auto&& word : m_words)
|
for (auto&& word : m_words)
|
||||||
{
|
{
|
||||||
if ((letters & word.second.letters) == letters and
|
if ((letters & word.second.letters) == letters and
|
||||||
|
|
Loading…
Reference in New Issue
Block a user