Regex: Introduce a Regex memory domain to track usage separately
This commit is contained in:
parent
9ec175f2f8
commit
8b2297f5ca
|
@ -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);
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue
Block a user