diff options
| author | Maxime Coste <mawww@kakoune.org> | 2017-10-15 09:23:57 +0800 |
|---|---|---|
| committer | Maxime Coste <mawww@kakoune.org> | 2017-11-01 14:05:14 +0800 |
| commit | 8b2297f5cafcd413fdf7fbd774c464496717008d (patch) | |
| tree | a87c07452e986646e514d1963c72418f65dc09d3 /src | |
| parent | 9ec175f2f8880a63e169506cab88c41e7637bc40 (diff) | |
Regex: Introduce a Regex memory domain to track usage separately
Diffstat (limited to 'src')
| -rw-r--r-- | src/memory.hh | 2 | ||||
| -rw-r--r-- | src/regex_impl.cc | 14 | ||||
| -rw-r--r-- | 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<AstNodePtr> children; + Vector<AstNodePtr, MemoryDomain::Regex> children; }; AstNodePtr ast; size_t capture_count; - Vector<std::function<bool (Codepoint)>> matchers; + Vector<std::function<bool (Codepoint)>, 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<CharRange>& ranges) + void normalize_ranges(Vector<CharRange, MemoryDomain::Regex>& ranges) { if (ranges.empty()) return; @@ -347,9 +347,9 @@ private: if (negative) ++m_pos; - Vector<CharRange> ranges; - Vector<Codepoint> excluded; - Vector<std::pair<wctype_t, bool>> ctypes; + Vector<CharRange, MemoryDomain::Regex> ranges; + Vector<Codepoint, MemoryDomain::Regex> excluded; + Vector<std::pair<wctype_t, bool>, 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<ParsedRegex::AstNodePtr>& characters, + uint32_t push_lookaround(ArrayView<const ParsedRegex::AstNodePtr> 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<MemoryDomain::Regex> { enum Op : char { @@ -63,9 +63,9 @@ struct CompiledRegex : RefCountable explicit operator bool() const { return not instructions.empty(); } - Vector<Instruction> instructions; - Vector<std::function<bool (Codepoint)>> matchers; - Vector<Codepoint> lookarounds; + Vector<Instruction, MemoryDomain::Regex> instructions; + Vector<std::function<bool (Codepoint)>, MemoryDomain::Regex> matchers; + Vector<Codepoint, MemoryDomain::Regex> 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<Thread> current_threads; - Vector<Thread> next_threads; + Vector<Thread, MemoryDomain::Regex> current_threads; + Vector<Thread, MemoryDomain::Regex> next_threads; uint16_t step = -1; }; @@ -489,7 +489,7 @@ private: Utf8It m_end; RegexExecFlags m_flags; - Vector<Saves*> m_saves; + Vector<Saves*, MemoryDomain::Regex> m_saves; Saves* m_first_free = nullptr; Saves* m_captures = nullptr; |
