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,
|
Remote,
|
||||||
Events,
|
Events,
|
||||||
Completion,
|
Completion,
|
||||||
|
Regex,
|
||||||
Count
|
Count
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -66,6 +67,7 @@ inline const char* domain_name(MemoryDomain domain)
|
||||||
case MemoryDomain::Remote: return "Remote";
|
case MemoryDomain::Remote: return "Remote";
|
||||||
case MemoryDomain::Events: return "Events";
|
case MemoryDomain::Events: return "Events";
|
||||||
case MemoryDomain::Completion: return "Completion";
|
case MemoryDomain::Completion: return "Completion";
|
||||||
|
case MemoryDomain::Regex: return "Regex";
|
||||||
case MemoryDomain::Count: break;
|
case MemoryDomain::Count: break;
|
||||||
}
|
}
|
||||||
kak_assert(false);
|
kak_assert(false);
|
||||||
|
|
|
@ -74,12 +74,12 @@ struct ParsedRegex
|
||||||
bool ignore_case;
|
bool ignore_case;
|
||||||
Codepoint value;
|
Codepoint value;
|
||||||
Quantifier quantifier;
|
Quantifier quantifier;
|
||||||
Vector<AstNodePtr> children;
|
Vector<AstNodePtr, MemoryDomain::Regex> children;
|
||||||
};
|
};
|
||||||
|
|
||||||
AstNodePtr ast;
|
AstNodePtr ast;
|
||||||
size_t capture_count;
|
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
|
// Recursive descent parser based on naming used in the ECMAScript
|
||||||
|
@ -317,7 +317,7 @@ private:
|
||||||
|
|
||||||
struct CharRange { Codepoint min, max; };
|
struct CharRange { Codepoint min, max; };
|
||||||
|
|
||||||
void normalize_ranges(Vector<CharRange>& ranges)
|
void normalize_ranges(Vector<CharRange, MemoryDomain::Regex>& ranges)
|
||||||
{
|
{
|
||||||
if (ranges.empty())
|
if (ranges.empty())
|
||||||
return;
|
return;
|
||||||
|
@ -347,9 +347,9 @@ private:
|
||||||
if (negative)
|
if (negative)
|
||||||
++m_pos;
|
++m_pos;
|
||||||
|
|
||||||
Vector<CharRange> ranges;
|
Vector<CharRange, MemoryDomain::Regex> ranges;
|
||||||
Vector<Codepoint> excluded;
|
Vector<Codepoint, MemoryDomain::Regex> excluded;
|
||||||
Vector<std::pair<wctype_t, bool>> ctypes;
|
Vector<std::pair<wctype_t, bool>, MemoryDomain::Regex> ctypes;
|
||||||
while (m_pos != m_regex.end() and *m_pos != ']')
|
while (m_pos != m_regex.end() and *m_pos != ']')
|
||||||
{
|
{
|
||||||
auto cp = *m_pos++;
|
auto cp = *m_pos++;
|
||||||
|
@ -761,7 +761,7 @@ private:
|
||||||
return res;
|
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)
|
bool reversed, bool ignore_case)
|
||||||
{
|
{
|
||||||
uint32_t res = m_program.lookarounds.size();
|
uint32_t res = m_program.lookarounds.size();
|
||||||
|
|
|
@ -23,7 +23,7 @@ enum class MatchDirection
|
||||||
Backward
|
Backward
|
||||||
};
|
};
|
||||||
|
|
||||||
struct CompiledRegex : RefCountable
|
struct CompiledRegex : RefCountable, UseMemoryDomain<MemoryDomain::Regex>
|
||||||
{
|
{
|
||||||
enum Op : char
|
enum Op : char
|
||||||
{
|
{
|
||||||
|
@ -63,9 +63,9 @@ struct CompiledRegex : RefCountable
|
||||||
|
|
||||||
explicit operator bool() const { return not instructions.empty(); }
|
explicit operator bool() const { return not instructions.empty(); }
|
||||||
|
|
||||||
Vector<Instruction> instructions;
|
Vector<Instruction, MemoryDomain::Regex> instructions;
|
||||||
Vector<std::function<bool (Codepoint)>> matchers;
|
Vector<std::function<bool (Codepoint)>, MemoryDomain::Regex> matchers;
|
||||||
Vector<Codepoint> lookarounds;
|
Vector<Codepoint, MemoryDomain::Regex> lookarounds;
|
||||||
MatchDirection direction;
|
MatchDirection direction;
|
||||||
size_t save_count;
|
size_t save_count;
|
||||||
|
|
||||||
|
@ -124,7 +124,7 @@ public:
|
||||||
for (size_t i = m_program.save_count-1; i > 0; --i)
|
for (size_t i = m_program.save_count-1; i > 0; --i)
|
||||||
saves->pos[i].~Iterator();
|
saves->pos[i].~Iterator();
|
||||||
saves->~Saves();
|
saves->~Saves();
|
||||||
::operator delete(saves);
|
operator delete(saves);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -211,7 +211,7 @@ private:
|
||||||
return res;
|
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{}}};
|
Saves* saves = new (ptr) Saves{{1}, {copy ? pos[0] : Iterator{}}};
|
||||||
for (size_t i = 1; i < count; ++i)
|
for (size_t i = 1; i < count; ++i)
|
||||||
new (&saves->pos[i]) Iterator{copy ? pos[i] : Iterator{}};
|
new (&saves->pos[i]) Iterator{copy ? pos[i] : Iterator{}};
|
||||||
|
@ -240,8 +240,8 @@ private:
|
||||||
|
|
||||||
struct ExecState
|
struct ExecState
|
||||||
{
|
{
|
||||||
Vector<Thread> current_threads;
|
Vector<Thread, MemoryDomain::Regex> current_threads;
|
||||||
Vector<Thread> next_threads;
|
Vector<Thread, MemoryDomain::Regex> next_threads;
|
||||||
uint16_t step = -1;
|
uint16_t step = -1;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -489,7 +489,7 @@ private:
|
||||||
Utf8It m_end;
|
Utf8It m_end;
|
||||||
RegexExecFlags m_flags;
|
RegexExecFlags m_flags;
|
||||||
|
|
||||||
Vector<Saves*> m_saves;
|
Vector<Saves*, MemoryDomain::Regex> m_saves;
|
||||||
Saves* m_first_free = nullptr;
|
Saves* m_first_free = nullptr;
|
||||||
|
|
||||||
Saves* m_captures = nullptr;
|
Saves* m_captures = nullptr;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user