mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-26 12:53:13 +00:00
Don't use std::map::insert when we need to overwrite values
This commit is contained in:
parent
1d54bff385
commit
afd8d2f9ba
2 changed files with 7 additions and 8 deletions
13
env.cpp
13
env.cpp
|
@ -901,8 +901,7 @@ int env_set(const wcstring &key, const wchar_t *val, int var_mode)
|
|||
}
|
||||
|
||||
entry->val = val;
|
||||
|
||||
node->env.insert(std::pair<wcstring, var_entry_t*>(key, entry));
|
||||
node->env[key] = entry;
|
||||
|
||||
if( entry->exportv )
|
||||
{
|
||||
|
@ -1397,7 +1396,8 @@ static void get_exported( const env_node_t *n, std::map<wcstring, wcstring> &h )
|
|||
var_entry_t *val_entry = iter->second;
|
||||
if( val_entry->exportv && (val_entry->val != ENV_NULL ) )
|
||||
{
|
||||
h.insert(std::pair<wcstring, wcstring>(key, val_entry->val));
|
||||
// Don't use std::map::insert here, since we need to overwrite existing values from previous scopes
|
||||
h[key] = val_entry->val;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1455,12 +1455,11 @@ static void update_export_array_if_necessary(bool recalc) {
|
|||
const wcstring &key = uni.at(i);
|
||||
const wchar_t *val = env_universal_get( key.c_str() );
|
||||
|
||||
std::map<wcstring, wcstring>::iterator result = vals.find( key );
|
||||
if( wcscmp( val, ENV_NULL) && ( result == vals.end() ) )
|
||||
{
|
||||
if (wcscmp( val, ENV_NULL)) {
|
||||
// Note that std::map::insert does NOT overwrite a value already in the map,
|
||||
// which we depend on here
|
||||
vals.insert(std::pair<wcstring, wcstring>(key, val));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
std::vector<std::string> local_export_buffer;
|
||||
|
|
|
@ -555,7 +555,7 @@ void env_universal_common_set( const wchar_t *key, const wchar_t *val, int expor
|
|||
entry->val = val;
|
||||
env_universal_common_remove( key );
|
||||
|
||||
env_universal_var.insert( std::pair<wcstring, var_uni_entry_t*>(key, entry));
|
||||
env_universal_var[key] = entry;
|
||||
if( callback )
|
||||
{
|
||||
callback( exportv?SET_EXPORT:SET, key, val );
|
||||
|
|
Loading…
Reference in a new issue