Skip to content

Commit 1c88d55

Browse files
author
Hana Dusíková
committed
ability to disable greedy optimization with macro CTRE_DISABLE_GREEDY_OPT
1 parent 6478da9 commit 1c88d55

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

include/ctre/evaluation.hpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,9 @@ template <typename... T> struct identify_type;
271271
template <typename R, typename Iterator, typename EndIterator, size_t A, size_t B, typename... Content, typename... Tail>
272272
constexpr CTRE_FORCE_INLINE R evaluate(const Iterator begin, Iterator current, const EndIterator end, R captures, [[maybe_unused]] ctll::list<repeat<A,B,Content...>, Tail...> stack) {
273273
// check if it can be optimized
274+
#ifndef CTRE_DISABLE_GREEDY_OPT
274275
if constexpr (collides(calculate_first(Content{}...), calculate_first(Tail{}...))) {
276+
#endif
275277
// A..B
276278
size_t i{0};
277279
for (; i < A && (A != 0); ++i) {
@@ -284,11 +286,12 @@ constexpr CTRE_FORCE_INLINE R evaluate(const Iterator begin, Iterator current, c
284286
}
285287

286288
return evaluate_recursive(i, begin, current, end, captures, stack);
289+
#ifndef CTRE_DISABLE_GREEDY_OPT
287290
} else {
288291
// if there is no collision we can go possessive
289292
return evaluate(begin, current, end, captures, ctll::list<possessive_repeat<A,B,Content...>, Tail...>());
290293
}
291-
294+
#endif
292295

293296
}
294297

single-header/ctre.hpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2831,6 +2831,15 @@ template <typename CB> constexpr int64_t negative_helper(ctre::enumeration<>, CB
28312831
return start;
28322832
}
28332833

2834+
template <typename CB> constexpr int64_t negative_helper(ctre::set<>, CB &, int64_t start) {
2835+
return start;
2836+
}
2837+
2838+
template <typename Head, typename... Rest, typename CB> constexpr int64_t negative_helper(ctre::set<Head, Rest...>, CB & cb, int64_t start) {
2839+
start = negative_helper(Head{}, cb, start);
2840+
return negative_helper(ctre::set<Rest...>{}, cb, start);
2841+
}
2842+
28342843
template <typename Head, typename... Rest, typename CB> constexpr void negative_helper(ctre::negative_set<Head, Rest...>, CB && cb, int64_t start = std::numeric_limits<int64_t>::min()) {
28352844
start = negative_helper(Head{}, cb, start);
28362845
negative_helper(ctre::negative_set<Rest...>{}, std::forward<CB>(cb), start);
@@ -3252,7 +3261,9 @@ template <typename... T> struct identify_type;
32523261
template <typename R, typename Iterator, typename EndIterator, size_t A, size_t B, typename... Content, typename... Tail>
32533262
constexpr CTRE_FORCE_INLINE R evaluate(const Iterator begin, Iterator current, const EndIterator end, R captures, [[maybe_unused]] ctll::list<repeat<A,B,Content...>, Tail...> stack) {
32543263
// check if it can be optimized
3264+
#ifndef CTRE_DISABLE_GREEDY_OPT
32553265
if constexpr (collides(calculate_first(Content{}...), calculate_first(Tail{}...))) {
3266+
#endif
32563267
// A..B
32573268
size_t i{0};
32583269
for (; i < A && (A != 0); ++i) {
@@ -3265,11 +3276,12 @@ constexpr CTRE_FORCE_INLINE R evaluate(const Iterator begin, Iterator current, c
32653276
}
32663277

32673278
return evaluate_recursive(i, begin, current, end, captures, stack);
3279+
#ifndef CTRE_DISABLE_GREEDY_OPT
32683280
} else {
32693281
// if there is no collision we can go possessive
32703282
return evaluate(begin, current, end, captures, ctll::list<possessive_repeat<A,B,Content...>, Tail...>());
32713283
}
3272-
3284+
#endif
32733285

32743286
}
32753287

0 commit comments

Comments
 (0)