Regex: Ensure we only ever have a single thread on a given instruction
This commit is contained in:
parent
ee42c6b0ba
commit
a9a04e81b0
|
@ -311,10 +311,13 @@ struct ThreadedExecutor
|
|||
return { StepResult::Consumed, inst };
|
||||
case RegexProgram::Jump:
|
||||
inst = m_program.begin() + *reinterpret_cast<const RegexProgram::Offset*>(inst);
|
||||
// if instruction is already going to be executed, drop this thread
|
||||
if (std::find(m_threads.begin(), m_threads.end(), inst) != m_threads.end())
|
||||
return { StepResult::Failed };
|
||||
break;
|
||||
case RegexProgram::Split:
|
||||
{
|
||||
m_threads.push_back(m_program.begin() + *reinterpret_cast<const RegexProgram::Offset*>(inst));
|
||||
add_thread(*reinterpret_cast<const RegexProgram::Offset*>(inst));
|
||||
inst += sizeof(RegexProgram::Offset);
|
||||
break;
|
||||
}
|
||||
|
@ -362,6 +365,13 @@ struct ThreadedExecutor
|
|||
return false;
|
||||
}
|
||||
|
||||
void add_thread(RegexProgram::Offset pos)
|
||||
{
|
||||
const char* inst = m_program.begin() + pos;
|
||||
if (std::find(m_threads.begin(), m_threads.end(), inst) == m_threads.end())
|
||||
m_threads.push_back(inst);
|
||||
}
|
||||
|
||||
bool is_line_start() const
|
||||
{
|
||||
return m_pos == m_subject.begin() or *(m_pos-1) == '\n';
|
||||
|
|
Loading…
Reference in New Issue
Block a user