From fc6e8e50fe85469890624c7cc8a020737d51ee77 Mon Sep 17 00:00:00 2001 From: Andreev Gregory Date: Wed, 31 Jul 2024 22:19:14 +0300 Subject: [PATCH] Optimized compilational algorithm: reduced output binary --- building/main.cpp | 4 ---- src/libregexis024fa/graph_to_bytecode/core.cpp | 14 +++++++++++--- src/libregexis024fa/graph_to_bytecode/filter.cpp | 14 +++++++++----- src/libregexis024fa/graph_to_bytecode/filter.h | 6 ------ 4 files changed, 20 insertions(+), 18 deletions(-) diff --git a/building/main.cpp b/building/main.cpp index 0893b5e..67ceaca 100644 --- a/building/main.cpp +++ b/building/main.cpp @@ -1,9 +1,5 @@ #include -/* - * LIBREGEXIS024 SPECIFIC BUILD COMMANDS BEGIN - */ - struct Libregexis024BuildSystem { /* Building runlevel */ BuildUnitsArray runlevel_1; diff --git a/src/libregexis024fa/graph_to_bytecode/core.cpp b/src/libregexis024fa/graph_to_bytecode/core.cpp index dc189bc..c98f57d 100644 --- a/src/libregexis024fa/graph_to_bytecode/core.cpp +++ b/src/libregexis024fa/graph_to_bytecode/core.cpp @@ -44,11 +44,17 @@ namespace regexis024 { FA_NodeOfOneCharRead* ocr = dynamic_cast(node); nonthrowing_assert(read_ss_ns < UINT32_MAX); cmd_READ(result, read_ss_ns++); - write_filter(result, bookmark_manager, {ocr->filter},{nodesBookmark(ocr->nxt_node)}); + addBranching(ocr->nxt_node); + bool can_spill = write_filter(result, bookmark_manager, {ocr->filter},{nodesBookmark(ocr->nxt_node)}); + if (!can_spill) + break; node = ocr->nxt_node; } else if (node->type == look_one_behind) { FA_NodeOfLookOneBehind* lob = dynamic_cast(node); - write_filter(result, bookmark_manager, {lob->filter}, {nodesBookmark(lob->nxt_node)}); + addBranching(lob->nxt_node); + bool can_spill = write_filter(result, bookmark_manager, {lob->filter}, {nodesBookmark(lob->nxt_node)}); + if (!can_spill) + break; node = lob->nxt_node; } else if (node->type == forking) { FA_NodeOfForking* fn = dynamic_cast(node); @@ -90,7 +96,9 @@ namespace regexis024 { branches.push_back(nodesBookmark(p.nxt_node)); addBranching(p.nxt_node); } - write_filter(result, bookmark_manager, codesets, branches); + bool can_spill = write_filter(result, bookmark_manager, codesets, branches); + if (!can_spill) + break; if (dcc->crossroads.empty()) break; node = dcc->crossroads[0].nxt_node; diff --git a/src/libregexis024fa/graph_to_bytecode/filter.cpp b/src/libregexis024fa/graph_to_bytecode/filter.cpp index e438a48..8051a4a 100644 --- a/src/libregexis024fa/graph_to_bytecode/filter.cpp +++ b/src/libregexis024fa/graph_to_bytecode/filter.cpp @@ -5,6 +5,12 @@ #include namespace regexis024 { + struct FilterSegment { + ssize_t color; + uint32_t L; + uint32_t R; + }; + std::vector convert_to_compSeg(const std::vector& crossroad_codesets) { std::vector compSeg; @@ -63,11 +69,9 @@ namespace regexis024 { size_t Ri; bool second_part = false; bookmark_id_t to_the_right_part; - - RecFrame(size_t li, size_t ri): Li(li),Ri(ri) {} }; - std::vector call_stack = {RecFrame(0, N - 1)}; + std::vector call_stack = {RecFrame{0, N - 1}}; auto is_sandwich = [&](size_t Li, size_t Ri) -> bool { return Li + 2 == Ri && compSeg[Li].color == compSeg[Ri].color && compSeg[Li + 1].L == compSeg[Li + 1].R; @@ -105,12 +109,12 @@ namespace regexis024 { cmd_JCGRTR(result, bookmark_manager, compSeg[m].R, cur_frame.to_the_right_part); cur_frame.second_part = true; /* cur_frame was just invalidated */ - call_stack.emplace_back(Li, m); + call_stack.push_back({Li, m}); } else { bookmark_manager.land_bookmark(result, cur_frame.to_the_right_part); /* cur_frame was invalidated */ call_stack.pop_back(); - call_stack.emplace_back(m + 1, Ri); + call_stack.push_back({m + 1, Ri}); } } } diff --git a/src/libregexis024fa/graph_to_bytecode/filter.h b/src/libregexis024fa/graph_to_bytecode/filter.h index 31c9cc1..3c6252e 100644 --- a/src/libregexis024fa/graph_to_bytecode/filter.h +++ b/src/libregexis024fa/graph_to_bytecode/filter.h @@ -7,12 +7,6 @@ #include namespace regexis024 { - struct FilterSegment { - ssize_t color; - uint32_t L; - uint32_t R; - }; - /* Return whether user of function must place [0]'th option after the filter * The filter can end up being written in such a way that the end will never be reached */ bool write_filter(std::vector& result, explicit_bookmarks& bookmark_manager,