aboutsummaryrefslogtreecommitdiffhomepage
path: root/common.cpp
diff options
context:
space:
mode:
authorGravatar ridiculousfish <corydoras@ridiculousfish.com>2014-02-24 09:54:30 -0800
committerGravatar ridiculousfish <corydoras@ridiculousfish.com>2014-02-24 09:54:30 -0800
commit688ea28bed24ce74ab47f20f0f9471d7d4c8c1a2 (patch)
tree6349b61d51a6995897af3038d0946bdeb527b6da /common.cpp
parent5e7c01c2518d0e0dd412f675b48ac59e8e84dc93 (diff)
Optimize the tokenize_variable_array hot spot to do less string copying
Diffstat (limited to 'common.cpp')
-rw-r--r--common.cpp13
1 files changed, 8 insertions, 5 deletions
diff --git a/common.cpp b/common.cpp
index f2240b53..08e8d7a1 100644
--- a/common.cpp
+++ b/common.cpp
@@ -1674,14 +1674,17 @@ int common_get_height()
void tokenize_variable_array(const wcstring &val, std::vector<wcstring> &out)
{
size_t pos = 0, end = val.size();
- while (pos < end)
+ while (pos <= end)
{
size_t next_pos = val.find(ARRAY_SEP, pos);
- if (next_pos == wcstring::npos) break;
- out.push_back(val.substr(pos, next_pos - pos));
- pos = next_pos + 1; //skip the separator
+ if (next_pos == wcstring::npos)
+ {
+ next_pos = end;
+ }
+ out.resize(out.size() + 1);
+ out.back().assign(val, pos, next_pos - pos);
+ pos = next_pos + 1; //skip the separator, or skip past the end
}
- out.push_back(val.substr(pos, end - pos));
}
bool string_prefixes_string(const wchar_t *proposed_prefix, const wcstring &value)