From 9fadaf278641623a36cb1e444afaa9930be4a711 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Tue, 3 May 2016 09:10:08 +0100 Subject: Precompile regexen for dependencies --- gentoobrowse-api/service/depend.cpp | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/gentoobrowse-api/service/depend.cpp b/gentoobrowse-api/service/depend.cpp index f93787e..fad6b64 100644 --- a/gentoobrowse-api/service/depend.cpp +++ b/gentoobrowse-api/service/depend.cpp @@ -1,18 +1,18 @@ #include "depend.h" #include -const Glib::ustring WhenUse_Begin("\\s*(!?[[:alnum:]-_]+)\\?\\s*\\(\\s*"); -const Glib::ustring WhenUse_End("\\s*\\)\\s*"); -const Glib::ustring Or_Begin("\\s*\\|\\|\\s*\\(\\s*"); -const Glib::ustring Or_Group("\\s*\\(\\s*"); -const Glib::ustring Or_End("\\s*\\)\\s*"); -const Glib::ustring AtomSpec("\\s*" +Gentoo::Utils::Lexer::PatternPtr WhenUse_Begin(Gentoo::Utils::Lexer::regex("\\s*(!?[[:alnum:]-_]+)\\?\\s*\\(\\s*", G_REGEX_OPTIMIZE)); +Gentoo::Utils::Lexer::PatternPtr WhenUse_End(Gentoo::Utils::Lexer::regex("\\s*\\)\\s*", G_REGEX_OPTIMIZE)); +Gentoo::Utils::Lexer::PatternPtr Or_Begin(Gentoo::Utils::Lexer::regex("\\s*\\|\\|\\s*\\(\\s*", G_REGEX_OPTIMIZE)); +Gentoo::Utils::Lexer::PatternPtr Or_Group(Gentoo::Utils::Lexer::regex("\\s*\\(\\s*", G_REGEX_OPTIMIZE)); +Gentoo::Utils::Lexer::PatternPtr Or_End(Gentoo::Utils::Lexer::regex("\\s*\\)\\s*", G_REGEX_OPTIMIZE)); +Gentoo::Utils::Lexer::PatternPtr AtomSpec(Gentoo::Utils::Lexer::regex("\\s*" "([[:punct:]]+)?" // op "([[:alnum:]-]+)\\/" // cat "(((-?[[:alpha:]]+[[:digit:]]+)|[[:alpha:]_+]|(-[[:alpha:]]))+)" // package "(-([0-9][.0-9]*[[:alpha:]]?\\*?(_(alpha|beta|pre|rc|p))?[[:digit:]]*(-r[[:digit:]]+)?))?" // version "(:([^/ []+(\\/[^ []+)?))?" // slot - "(\\[([^]]+)\\])?\\s*"); // use + "(\\[([^]]+)\\])?\\s*", G_REGEX_OPTIMIZE)); // use const std::string InWhen("InWhen"); const std::string InOr("InOr"); @@ -40,29 +40,29 @@ namespace Portage { Depend::Depend() { // use? ( - rules.push_back({ { InitialState, InWhen, InOr }, regex(WhenUse_Begin), [this](auto es) { + rules.push_back({ { InitialState, InWhen, InOr }, WhenUse_Begin, [this](auto es) { es->pushState(InWhen); when.push_back(*es->pattern->match(1)); } }); // ) - rules.push_back({ { InWhen }, regex(WhenUse_End), [this](auto es) { + rules.push_back({ { InWhen }, WhenUse_End, [this](auto es) { es->popState(); when.pop_back(); } }); // || ( - rules.push_back({ { InitialState, InWhen, InOr }, regex(Or_Begin), [this](auto es) { + rules.push_back({ { InitialState, InWhen, InOr }, Or_Begin, [this](auto es) { es->pushState(InOr); } }); // || ( - rules.push_back({ { InOr }, regex(Or_Group), [this](auto es) { + rules.push_back({ { InOr }, Or_Group, [this](auto es) { es->pushState(InOr); } }); // ) - rules.push_back({ { InOr }, regex(Or_End), [this](auto es) { + rules.push_back({ { InOr }, Or_End, [this](auto es) { es->popState(); } }); // [op]some-cat/package[-version][:slot][uses] - rules.push_back({ { InitialState, InWhen, InOr }, regex(AtomSpec), [this](auto es) { + rules.push_back({ { InitialState, InWhen, InOr }, AtomSpec, [this](auto es) { ds.push_back(new Gentoo::Dependency( when, iuo(es->pattern->match(1)), // op -- cgit v1.2.3