Skip to content

Commit 8b3dccb

Browse files
committed
Use both iterators from string search (no need to double check string matches)
1 parent 08d6249 commit 8b3dccb

File tree

1 file changed

+18
-14
lines changed

1 file changed

+18
-14
lines changed

include/ctre/wrapper.hpp

+18-14
Original file line numberDiff line numberDiff line change
@@ -67,23 +67,27 @@ struct search_method {
6767

6868
auto it = begin;
6969
if constexpr (is_string(front_re{}.front) && size(front_re{}.list)) {
70-
it = search_for_string(it, end, front_re{}.front).position;
71-
for (; end != it;) {
72-
if (auto out = evaluate(orig_begin, it, end, Modifier{}, return_type<result_iterator, RE>{}, ctll::list<start_mark, sequence<decltype(front_re{}.front), decltype(make_into_sequence(front_re{}.list))>, end_mark, accept>())) {
73-
return out;
70+
auto it2 = search_for_string(it, end, front_re{}.front);
71+
return_type<result_iterator, RE> result{};
72+
for (; end != it2.position;) {
73+
result.set_start_mark(it2.position);
74+
if (result = evaluate(orig_begin, it2.end_position, end, Modifier{}, result, ctll::list<start_mark, decltype(make_into_sequence(front_re{}.list)), end_mark, accept>())) {
75+
return result;
7476
}
75-
it = search_for_string(++it, end, front_re{}.front).position;
77+
result.unmatch();
78+
std::advance(it2.position, 1);
79+
it2 = search_for_string(it2.position, end, front_re{}.front);
7680
}
77-
return evaluate(orig_begin, it, end, Modifier{}, return_type<result_iterator, RE>{}, ctll::list<start_mark, sequence<decltype(front_re{}.front), decltype(make_into_sequence(front_re{}.list))>, end_mark, accept>());
81+
result.set_start_mark(it2.position);
82+
return result = evaluate(orig_begin, it2.end_position, end, Modifier{}, result, ctll::list<start_mark, decltype(make_into_sequence(front_re{}.list)), end_mark, accept>());
7883
} else if (is_string(front_re{}.front)) {
79-
it = search_for_string(it, end, front_re{}.front).position;
80-
for (; end != it;) {
81-
if (auto out = evaluate(orig_begin, it, end, Modifier{}, return_type<result_iterator, RE>{}, ctll::list<start_mark, decltype(front_re{}.front), end_mark, accept>())) {
82-
return out;
83-
}
84-
it = search_for_string(++it, end, front_re{}.front).position;
85-
}
86-
return evaluate(orig_begin, it, end, Modifier{}, return_type<result_iterator, RE>{}, ctll::list<start_mark, decltype(front_re{}.front), end_mark, accept>());
84+
auto it2 = search_for_string(it, end, front_re{}.front);
85+
return_type<result_iterator, RE> result{};
86+
result.set_start_mark(it2.position);
87+
result.set_end_mark(it2.end_position);
88+
if (it2.match)
89+
result.matched();
90+
return result;
8791
} else {
8892
for (; end != it && !fixed; ++it) {
8993
if (auto out = evaluate(orig_begin, it, end, Modifier{}, return_type<result_iterator, RE>{}, ctll::list<start_mark, RE, end_mark, accept>())) {

0 commit comments

Comments
 (0)