1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 13:07:46 +00:00

LibRegex: Add a basic optimization pass

This currently tries to convert forking loops to atomic groups, and
unify the left side of alternations.
This commit is contained in:
Ali Mohammad Pur 2021-09-12 17:30:27 +04:30 committed by Ali Mohammad Pur
parent 913382734c
commit 246ab432ff
9 changed files with 677 additions and 24 deletions

View file

@ -24,6 +24,15 @@
namespace regex {
namespace Detail {
struct Block {
size_t start;
size_t end;
};
}
static constexpr const size_t c_max_recursion = 5000;
static constexpr const size_t c_match_preallocation_count = 0;
@ -217,6 +226,12 @@ public:
RegexResult result = matcher->match(views, AllOptions { regex_options.value_or({}) } | AllFlags::SkipSubExprResults);
return result.success;
}
private:
void run_optimization_passes();
using BasicBlockList = Vector<Detail::Block>;
BasicBlockList split_basic_blocks();
void attempt_rewrite_loops_as_atomic_groups(BasicBlockList const&);
};
// free standing functions for match, search and has_match