Skip to content

Unrolling selection optimization #94

@Andersama

Description

@Andersama

Not sure how to go about this with parsing rules, or for all cases.
See: http://www.rexegg.com/regex-optimizations.html#staralt

// (greedy) repeat of alternation (?:a|b...)* -> a*(?:b...+a*)*
template <typename R, typename Iterator, typename EndIterator, typename A, typename... Content, typename... Tail>
constexpr CTRE_FORCE_INLINE R evaluate(const Iterator begin, Iterator current, const EndIterator end, R captures, ctll::list<repeat<0, 0, sequence<select<A,Content...>>>, Tail...>) noexcept {
	return evaluate(begin, current, end, captures, ctll::list<star<A>, star<plus<select<Content...>>, star<A>>, Tail...>());
}

// (greedy) repeat of alternation (?:a|b...)* -> a*(?:b...+a*)*
template <typename R, typename Iterator, typename EndIterator, typename A, typename... Content, typename... Tail>
constexpr CTRE_FORCE_INLINE R evaluate(const Iterator begin, Iterator current, const EndIterator end, R captures, ctll::list<repeat<0, 0, select<A, Content...>>, Tail...>) noexcept {
	return evaluate(begin, current, end, captures, ctll::list<star<A>, star<plus<select<Content...>>, star<A>>, Tail...>());
}

Pretty sure with some other overloads capture groups would also work. (a|b...)* -> (a)(?:(b...)+(a))*

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions