From a0a9b3ba0bb9d3ff7030f25614af4e22e0c8619a Mon Sep 17 00:00:00 2001 From: Ulya Trofimovich Date: Sun, 4 Oct 2015 19:46:34 +0100 Subject: [PATCH] Moved path-combining magic closer to path definition. --- re2c/src/codegen/skeleton/generate_data.cc | 9 +-------- re2c/src/codegen/skeleton/path.h | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/re2c/src/codegen/skeleton/generate_data.cc b/re2c/src/codegen/skeleton/generate_data.cc index a2b716cd..6e039f92 100644 --- a/re2c/src/codegen/skeleton/generate_data.cc +++ b/re2c/src/codegen/skeleton/generate_data.cc @@ -336,14 +336,7 @@ template delete [] buffer; // keys - const bool none = suffix.match ().is_none (); - const size_t len_match = none - ? prefix.len_matching () - : prefix_len + suffix.len_matching (); - const rule_rank_t match = none - ? prefix.match () - : suffix.match (); - keygen (keys, count, len, len_match, match); + keygen (keys, count, len, len_matching (prefix, suffix), match (prefix, suffix)); } return size; diff --git a/re2c/src/codegen/skeleton/path.h b/re2c/src/codegen/skeleton/path.h index c3476989..c30471d4 100644 --- a/re2c/src/codegen/skeleton/path.h +++ b/re2c/src/codegen/skeleton/path.h @@ -57,8 +57,29 @@ public: } arcs.insert (arcs.end (), p->arcs.begin (), p->arcs.end ()); } + + template + friend size_t len_matching (const generic_path_t & prefix, const generic_path_t & suffix); + template + friend rule_rank_t match (const generic_path_t & prefix, const generic_path_t & suffix); }; +template + size_t len_matching (const generic_path_t & prefix, const generic_path_t & suffix) +{ + return suffix.rule.is_none () + ? prefix.rule_pos + : prefix.arcs.size () + suffix.rule_pos; +} + +template + rule_rank_t match (const generic_path_t & prefix, const generic_path_t & suffix) +{ + return suffix.match ().is_none () + ? prefix.match () + : suffix.match (); +} + typedef generic_path_t path_t; typedef std::vector multiarc_t; -- 2.40.0