From 12abb54a8853b50df5815387946dbae8cf7dc448 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Mon, 9 Nov 2015 08:42:12 +0000 Subject: [PATCH] Slightly more performant regex capture gathering in select_all_matches --- src/selectors.cc | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/selectors.cc b/src/selectors.cc index 06257ad5..524ff9e1 100644 --- a/src/selectors.cc +++ b/src/selectors.cc @@ -570,6 +570,7 @@ void select_all_matches(SelectionList& selections, const Regex& regex) RegexIt re_it(buffer.iterator_at(sel.min()), sel_end, regex); RegexIt re_end; + const unsigned mark_count = regex.mark_count(); for (; re_it != re_end; ++re_it) { auto begin = ensure_char_start(buffer, (*re_it)[0].first); @@ -578,8 +579,10 @@ void select_all_matches(SelectionList& selections, const Regex& regex) auto end = ensure_char_start(buffer, (*re_it)[0].second); CaptureList captures; + captures.reserve(mark_count); for (auto& match : *re_it) - captures.emplace_back(match.first, match.second); + captures.push_back(buffer.string(match.first.coord(), + match.second.coord())); result.push_back( keep_direction({ begin.coord(),