Skip to content

Commit e9504fb

Browse files
committed
Select optimization: If all sub expressions are characters then we're evaluating a character class
In testing, compiles faster and generates assembly similar to -O3 even with -Os.
1 parent 9a37e55 commit e9504fb

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

Diff for: include/ctre/evaluation.hpp

+8-3
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,15 @@ constexpr CTRE_FORCE_INLINE R evaluate(const Iterator begin, Iterator current, c
136136
// matching select in patterns
137137
template <typename R, typename Iterator, typename EndIterator, typename HeadOptions, typename... TailOptions, typename... Tail>
138138
constexpr CTRE_FORCE_INLINE R evaluate(const Iterator begin, Iterator current, const EndIterator end, const flags & f, R captures, ctll::list<select<HeadOptions, TailOptions...>, Tail...>) noexcept {
139-
if (auto r = evaluate(begin, current, end, f, captures, ctll::list<HeadOptions, Tail...>())) {
140-
return r;
139+
if constexpr (MatchesCharacter<HeadOptions>::template value<decltype(*std::declval<Iterator>())> &&
140+
((MatchesCharacter<TailOptions>::template value<decltype(*std::declval<Iterator>())>) && ...)) {
141+
return evaluate(begin, current, end, f, captures, ctll::list<set<HeadOptions, TailOptions...>, Tail...>());
141142
} else {
142-
return evaluate(begin, current, end, f, captures, ctll::list<select<TailOptions...>, Tail...>());
143+
if (auto r = evaluate(begin, current, end, f, captures, ctll::list<HeadOptions, Tail...>())) {
144+
return r;
145+
} else {
146+
return evaluate(begin, current, end, f, captures, ctll::list<select<TailOptions...>, Tail...>());
147+
}
143148
}
144149
}
145150

0 commit comments

Comments
 (0)