mirror of
https://github.com/fish-shell/fish-shell.git
synced 2024-11-29 05:03:46 +08:00
Save a few string allocations when importing environment variables
This commit is contained in:
parent
3044697baa
commit
a37d4d809e
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue
Block a user