From a37d4d809e067e54dfaec74888bd668f1a1727d1 Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Sat, 5 Mar 2016 19:07:00 -0800 Subject: [PATCH] Save a few string allocations when importing environment variables --- src/env.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/env.cpp b/src/env.cpp index 28ea51b05..c24280bcc 100644 --- a/src/env.cpp +++ b/src/env.cpp @@ -450,6 +450,7 @@ void env_init(const struct config_paths_t *paths /* or NULL */) */ /* Import environment variables. Walk backwards so that the first one out of any duplicates wins (#2784) */ + wcstring key, val; const char * const * envp = (environ ? environ : __environ); size_t i = 0; while (envp && envp[i]) @@ -468,9 +469,9 @@ void env_init(const struct config_paths_t *paths /* or NULL */) } else { - wcstring key = key_and_val.substr(0, eql); + key.assign(key_and_val, 0, eql); if (is_read_only(key) || is_electric(key)) continue; - wcstring val = key_and_val.substr(eql + 1); + val.assign(key_and_val, eql + 1, wcstring::npos); if (variable_is_colon_delimited_array(key)) { std::replace(val.begin(), val.end(), L':', ARRAY_SEP);