summaryrefslogtreecommitdiff
path: root/src/string.cc
diff options
context:
space:
mode:
authorMaxime Coste <frrrwww@gmail.com>2015-03-14 11:46:53 +0000
committerMaxime Coste <frrrwww@gmail.com>2015-03-14 11:46:53 +0000
commit82833608c917178a4362f52819fcebd47dc8d112 (patch)
tree1758c31891dd6b8471302a553fcf99694efb0aa7 /src/string.cc
parent12a732d1faeba33a30e7e00efa9e474dd215c2fb (diff)
Allocate some data in advance in string algorithm
Diffstat (limited to 'src/string.cc')
-rw-r--r--src/string.cc4
1 files changed, 4 insertions, 0 deletions
diff --git a/src/string.cc b/src/string.cc
index 4e20a2c1..ba8403f7 100644
--- a/src/string.cc
+++ b/src/string.cc
@@ -59,6 +59,7 @@ Vector<StringView> split(StringView str, char separator)
String escape(StringView str, StringView characters, char escape)
{
String res;
+ res.reserve(str.length());
for (auto& c : str)
{
if (contains(characters, c))
@@ -71,6 +72,7 @@ String escape(StringView str, StringView characters, char escape)
String unescape(StringView str, StringView characters, char escape)
{
String res;
+ res.reserve(str.length());
for (auto& c : str)
{
if (contains(characters, c) and not res.empty() and res.back() == escape)
@@ -84,6 +86,7 @@ String unescape(StringView str, StringView characters, char escape)
String indent(StringView str, StringView indent)
{
String res;
+ res.reserve(str.length());
bool was_eol = true;
for (ByteCount i = 0; i < str.length(); ++i)
{
@@ -144,6 +147,7 @@ bool subsequence_match(StringView str, StringView subseq)
String expand_tabs(StringView line, CharCount tabstop, CharCount col)
{
String res;
+ res.reserve(line.length());
using Utf8It = utf8::iterator<const char*>;
for (Utf8It it = line.begin(); it.base() < line.end(); ++it)
{