From 8b2297f5cafcd413fdf7fbd774c464496717008d Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Sun, 15 Oct 2017 09:23:57 +0800 Subject: [PATCH] Regex: Introduce a Regex memory domain to track usage separately --- src/memory.hh | 2 ++ src/regex_impl.cc | 14 +++++++------- src/regex_impl.hh | 18 +++++++++--------- 3 files changed, 18 insertions(+), 16 deletions(-) diff --git a/src/memory.hh b/src/memory.hh index b25e687d..062081d1 100644 --- a/src/memory.hh +++ b/src/memory.hh @@ -36,6 +36,7 @@ enum class MemoryDomain Remote, Events, Completion, + Regex, Count }; @@ -66,6 +67,7 @@ inline const char* domain_name(MemoryDomain domain) case MemoryDomain::Remote: return "Remote"; case MemoryDomain::Events: return "Events"; case MemoryDomain::Completion: return "Completion"; + case MemoryDomain::Regex: return "Regex"; case MemoryDomain::Count: break; } kak_assert(false); diff --git a/src/regex_impl.cc b/src/regex_impl.cc index fee7dcb3..57300a51 100644 --- a/src/regex_impl.cc +++ b/src/regex_impl.cc @@ -74,12 +74,12 @@ struct ParsedRegex bool ignore_case; Codepoint value; Quantifier quantifier; - Vector children; + Vector children; }; AstNodePtr ast; size_t capture_count; - Vector> matchers; + Vector, MemoryDomain::Regex> matchers; }; // Recursive descent parser based on naming used in the ECMAScript @@ -317,7 +317,7 @@ private: struct CharRange { Codepoint min, max; }; - void normalize_ranges(Vector& ranges) + void normalize_ranges(Vector& ranges) { if (ranges.empty()) return; @@ -347,9 +347,9 @@ private: if (negative) ++m_pos; - Vector ranges; - Vector excluded; - Vector> ctypes; + Vector ranges; + Vector excluded; + Vector, MemoryDomain::Regex> ctypes; while (m_pos != m_regex.end() and *m_pos != ']') { auto cp = *m_pos++; @@ -761,7 +761,7 @@ private: return res; } - uint32_t push_lookaround(const Vector& characters, + uint32_t push_lookaround(ArrayView characters, bool reversed, bool ignore_case) { uint32_t res = m_program.lookarounds.size(); diff --git a/src/regex_impl.hh b/src/regex_impl.hh index 6e0ec046..27820605 100644 --- a/src/regex_impl.hh +++ b/src/regex_impl.hh @@ -23,7 +23,7 @@ enum class MatchDirection Backward }; -struct CompiledRegex : RefCountable +struct CompiledRegex : RefCountable, UseMemoryDomain { enum Op : char { @@ -63,9 +63,9 @@ struct CompiledRegex : RefCountable explicit operator bool() const { return not instructions.empty(); } - Vector instructions; - Vector> matchers; - Vector lookarounds; + Vector instructions; + Vector, MemoryDomain::Regex> matchers; + Vector lookarounds; MatchDirection direction; size_t save_count; @@ -124,7 +124,7 @@ public: for (size_t i = m_program.save_count-1; i > 0; --i) saves->pos[i].~Iterator(); saves->~Saves(); - ::operator delete(saves); + operator delete(saves); } } @@ -211,7 +211,7 @@ private: return res; } - void* ptr = ::operator new (sizeof(Saves) + (count-1) * sizeof(Iterator)); + void* ptr = operator new (sizeof(Saves) + (count-1) * sizeof(Iterator)); Saves* saves = new (ptr) Saves{{1}, {copy ? pos[0] : Iterator{}}}; for (size_t i = 1; i < count; ++i) new (&saves->pos[i]) Iterator{copy ? pos[i] : Iterator{}}; @@ -240,8 +240,8 @@ private: struct ExecState { - Vector current_threads; - Vector next_threads; + Vector current_threads; + Vector next_threads; uint16_t step = -1; }; @@ -489,7 +489,7 @@ private: Utf8It m_end; RegexExecFlags m_flags; - Vector m_saves; + Vector m_saves; Saves* m_first_free = nullptr; Saves* m_captures = nullptr;