Skip to content

Commit 93619fe

Browse files
committed
Optimize repetition of bracket expressions.
- Added support for `test` and `repeat` operations in the instruction object handling, improving flexibility in opcode processing. - Updated `is_repetition_expression_always_optimizable_v` to include `bracket_expression`, enhancing type trait capabilities. - Refactored `encode_min_max` calls for `char32_range_expression` and `bracket_expression` to utilize `add_rune_set`, optimizing rune set management.
1 parent d9d0dce commit 93619fe

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

include/lug/lug.hpp

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,14 @@ struct program
159159
if (new_instr.op < opcode::match) {
160160
std::optional<std::size_t> object;
161161
switch (new_instr.op) {
162-
case opcode::match_any_of: case opcode::match_all_of: case opcode::match_none_of: object = instr.immediate16 + uniforms_offset; break;
163-
case opcode::match_set: object = instr.immediate16 + runesets_offset; break;
162+
case opcode::match_any_of: case opcode::match_all_of: case opcode::match_none_of:
163+
case opcode::test_any_of: case opcode::test_all_of: case opcode::test_none_of:
164+
case opcode::repeat_any_of: case opcode::repeat_all_of: case opcode::repeat_none_of:
165+
object = instr.immediate16 + uniforms_offset;
166+
break;
167+
case opcode::match_set: case opcode::test_set: case opcode::repeat_set:
168+
object = instr.immediate16 + runesets_offset;
169+
break;
164170
case opcode::report_push: object = instr.immediate16 + handlers_offset; break;
165171
case opcode::predicate: object = instr.immediate16 + predicates_offset; break;
166172
case opcode::action: object = instr.immediate16 + actions_offset; break;
@@ -1365,7 +1371,8 @@ inline constexpr bool is_repetition_expression_always_optimizable_v =
13651371
std::is_same_v<E, ctype_expression<unicode::ctype::blank>> ||
13661372
std::is_same_v<E, ctype_expression<unicode::ctype::space>> ||
13671373
std::is_same_v<E, char_expression> ||
1368-
std::is_same_v<E, char32_range_expression>;
1374+
std::is_same_v<E, char32_range_expression> ||
1375+
std::is_same_v<E, bracket_expression>;
13691376

13701377
template <class E>
13711378
inline constexpr bool is_repetition_expression_optimizable_v =
@@ -1388,7 +1395,9 @@ template <std::size_t NMin, std::size_t NMax, class E>
13881395
else if constexpr (std::is_same_v<std::decay_t<E>, char_expression>)
13891396
d.encode_char_or_set(opcode::repeat_octet, opcode::repeat_set, e.c, NMin, NMax);
13901397
else if constexpr (std::is_same_v<std::decay_t<E>, char32_range_expression>)
1391-
d.encode_min_max(opcode::repeat_set, NMin, NMax, e.make_rune_set(d.mode()));
1398+
d.encode_min_max(opcode::repeat_set, NMin, NMax, d.add_rune_set(e.make_rune_set(d.mode())));
1399+
else if constexpr (std::is_same_v<std::decay_t<E>, bracket_expression>)
1400+
d.encode_min_max(opcode::repeat_set, NMin, NMax, d.add_rune_set(e.make_rune_set(d.mode())));
13921401
return true;
13931402
} else if constexpr (std::is_same_v<std::decay_t<E>, string_expression>) {
13941403
if (d.should_skip() || (e.text.size() != 1))

0 commit comments

Comments
 (0)