Regex: put the other char boolean inside the general start char map
This commit is contained in:
parent
7c3bc48627
commit
9e15207d2a
|
@ -14,6 +14,8 @@
|
||||||
namespace Kakoune
|
namespace Kakoune
|
||||||
{
|
{
|
||||||
|
|
||||||
|
constexpr Codepoint CompiledRegex::StartChars::other;
|
||||||
|
|
||||||
struct ParsedRegex
|
struct ParsedRegex
|
||||||
{
|
{
|
||||||
enum Op : char
|
enum Op : char
|
||||||
|
@ -837,8 +839,6 @@ private:
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
static constexpr size_t start_chars_count = CompiledRegex::StartChars::count;
|
|
||||||
|
|
||||||
// Fills accepted and rejected according to which chars can start the given node,
|
// Fills accepted and rejected according to which chars can start the given node,
|
||||||
// returns true if the node did not consume the char, hence a following node in
|
// returns true if the node did not consume the char, hence a following node in
|
||||||
// sequence would be still relevant for the parent node start chars computation.
|
// sequence would be still relevant for the parent node start chars computation.
|
||||||
|
@ -848,7 +848,7 @@ private:
|
||||||
switch (node->op)
|
switch (node->op)
|
||||||
{
|
{
|
||||||
case ParsedRegex::Literal:
|
case ParsedRegex::Literal:
|
||||||
if (node->value < start_chars_count)
|
if (node->value < CompiledRegex::StartChars::count)
|
||||||
{
|
{
|
||||||
if (node->ignore_case)
|
if (node->ignore_case)
|
||||||
{
|
{
|
||||||
|
@ -859,18 +859,18 @@ private:
|
||||||
start_chars.map[node->value] = true;
|
start_chars.map[node->value] = true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
start_chars.accept_other = true;
|
start_chars.map[CompiledRegex::StartChars::other] = true;
|
||||||
return node->quantifier.allows_none();
|
return node->quantifier.allows_none();
|
||||||
case ParsedRegex::AnyChar:
|
case ParsedRegex::AnyChar:
|
||||||
for (auto& b : start_chars.map)
|
for (auto& b : start_chars.map)
|
||||||
b = true;
|
b = true;
|
||||||
start_chars.accept_other = true;
|
start_chars.map[CompiledRegex::StartChars::other] = true;
|
||||||
return node->quantifier.allows_none();
|
return node->quantifier.allows_none();
|
||||||
case ParsedRegex::Matcher:
|
case ParsedRegex::Matcher:
|
||||||
for (Codepoint c = 0; c < start_chars_count; ++c)
|
for (Codepoint c = 0; c < CompiledRegex::StartChars::count; ++c)
|
||||||
if (m_program.matchers[node->value](c))
|
if (m_program.matchers[node->value](c))
|
||||||
start_chars.map[c] = true;
|
start_chars.map[c] = true;
|
||||||
start_chars.accept_other = true; // stay safe
|
start_chars.map[CompiledRegex::StartChars::other] = true; // stay safe
|
||||||
return node->quantifier.allows_none();
|
return node->quantifier.allows_none();
|
||||||
case ParsedRegex::Sequence:
|
case ParsedRegex::Sequence:
|
||||||
{
|
{
|
||||||
|
|
|
@ -76,9 +76,10 @@ struct CompiledRegex : RefCountable, UseMemoryDomain<MemoryDomain::Regex>
|
||||||
struct StartChars
|
struct StartChars
|
||||||
{
|
{
|
||||||
static constexpr size_t count = 256;
|
static constexpr size_t count = 256;
|
||||||
bool accept_other;
|
static constexpr Codepoint other = 256;
|
||||||
bool map[count];
|
bool map[count+1];
|
||||||
};
|
};
|
||||||
|
|
||||||
std::unique_ptr<StartChars> start_chars;
|
std::unique_ptr<StartChars> start_chars;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -437,8 +438,7 @@ private:
|
||||||
return;
|
return;
|
||||||
|
|
||||||
while (start != end and *start >= 0 and
|
while (start != end and *start >= 0 and
|
||||||
((*start < 256 and not start_chars->map[*start]) or
|
not start_chars->map[std::min(*start, CompiledRegex::StartChars::other)])
|
||||||
(*start >= 256 and not start_chars->accept_other)))
|
|
||||||
++start;
|
++start;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user