summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMaxime Coste <mawww@kakoune.org>2017-11-29 14:07:04 +0800
committerMaxime Coste <mawww@kakoune.org>2017-11-29 14:07:04 +0800
commit839da764e7e86c712e8383e5c593e322e09ae2d4 (patch)
tree237cfe584a83b4a2118bb43f87d0e823b469ffa5 /src
parentf950fe337684e916f1746b28bbd81ebd5c1e86f7 (diff)
Regex: avoid unneeded allocations and moves by reusing MatchResults storage
Diffstat (limited to 'src')
-rw-r--r--src/regex.hh14
1 files changed, 6 insertions, 8 deletions
diff --git a/src/regex.hh b/src/regex.hh
index 58f71270..4c7b8ecb 100644
--- a/src/regex.hh
+++ b/src/regex.hh
@@ -95,6 +95,8 @@ struct MatchResults
m_values.swap(other.m_values);
}
+ Vector<Iterator, MemoryDomain::Regex>& values() { return m_values; }
+
private:
Vector<Iterator, MemoryDomain::Regex> m_values;
};
@@ -116,10 +118,8 @@ bool regex_match(It begin, It end, const Regex& re)
template<typename It>
bool regex_match(It begin, It end, MatchResults<It>& res, const Regex& re)
{
- Vector<It, MemoryDomain::Regex> captures;
- const bool matched = regex_match(begin, end, captures, *re.impl());
- res = matched ? MatchResults<It>{std::move(captures)} : MatchResults<It>{};
- return matched;
+ res.values().clear();
+ return regex_match(begin, end, res.values(), *re.impl());
}
template<typename It>
@@ -133,10 +133,8 @@ template<typename It, MatchDirection direction = MatchDirection::Forward>
bool regex_search(It begin, It end, MatchResults<It>& res, const Regex& re,
RegexExecFlags flags = RegexExecFlags::None)
{
- Vector<It, MemoryDomain::Regex> captures;
- const bool matched = regex_search<It, direction>(begin, end, captures, *re.impl(), flags);
- res = matched ? MatchResults<It>{std::move(captures)} : MatchResults<It>{};
- return matched;
+ res.values().clear();
+ return regex_search<It, direction>(begin, end, res.values(), *re.impl(), flags);
}
String option_to_string(const Regex& re);