diff options
author | Björn Linse <bjorn.linse@gmail.com> | 2021-08-22 17:29:17 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-22 17:29:17 +0200 |
commit | 649dbb3b15949aee9d9e25cd39cca1e3e3a4ee45 (patch) | |
tree | dc153c0cf6ac08e6f0f5508dcc2603618f314ef6 /src/nvim/os/env.c | |
parent | db1b0ee3b30fd4cd323907c7f24bd575c22e68f0 (diff) | |
parent | de21e6ef3d9af96d2b71e54d8148d28b5fc9f22e (diff) | |
download | rneovim-649dbb3b15949aee9d9e25cd39cca1e3e3a4ee45.tar.gz rneovim-649dbb3b15949aee9d9e25cd39cca1e3e3a4ee45.tar.bz2 rneovim-649dbb3b15949aee9d9e25cd39cca1e3e3a4ee45.zip |
Merge pull request #15457 from bfredl/oldmap
refactor(map): remove extra-allocating map_new/map_free functions
Diffstat (limited to 'src/nvim/os/env.c')
-rw-r--r-- | src/nvim/os/env.c | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/src/nvim/os/env.c b/src/nvim/os/env.c index 008f5ef63b..92b5e14824 100644 --- a/src/nvim/os/env.c +++ b/src/nvim/os/env.c @@ -35,12 +35,11 @@ // Because `uv_os_getenv` requires allocating, we must manage a map to maintain // the behavior of `os_getenv`. -static PMap(cstr_t) *envmap; +static PMap(cstr_t) envmap = MAP_INIT; static uv_mutex_t mutex; void env_init(void) { - envmap = pmap_new(cstr_t)(); uv_mutex_init(&mutex); } @@ -66,8 +65,8 @@ const char *os_getenv(const char *name) } uv_mutex_lock(&mutex); int r = 0; - if (pmap_has(cstr_t)(envmap, name) - && !!(e = (char *)pmap_get(cstr_t)(envmap, name))) { + if (pmap_has(cstr_t)(&envmap, name) + && !!(e = (char *)pmap_get(cstr_t)(&envmap, name))) { if (e[0] != '\0') { // Found non-empty cached env var. // NOTE: This risks incoherence if an in-process library changes the @@ -75,7 +74,7 @@ const char *os_getenv(const char *name) // that turns out to be a problem, we can just remove this codepath. goto end; } - pmap_del2(envmap, name); + pmap_del2(&envmap, name); } e = xmalloc(size); r = uv_os_getenv(name, e, &size); @@ -88,7 +87,7 @@ const char *os_getenv(const char *name) e = NULL; goto end; } - pmap_put(cstr_t)(envmap, xstrdup(name), e); + pmap_put(cstr_t)(&envmap, xstrdup(name), e); end: // Must do this before ELOG, log.c may call os_setenv. uv_mutex_unlock(&mutex); @@ -157,7 +156,7 @@ int os_setenv(const char *name, const char *value, int overwrite) assert(r != UV_EINVAL); // Destroy the old map item. Do this AFTER uv_os_setenv(), because `value` // could be a previous os_getenv() result. - pmap_del2(envmap, name); + pmap_del2(&envmap, name); // Must do this before ELOG, log.c may call os_setenv. uv_mutex_unlock(&mutex); if (r != 0) { @@ -174,7 +173,7 @@ int os_unsetenv(const char *name) return -1; } uv_mutex_lock(&mutex); - pmap_del2(envmap, name); + pmap_del2(&envmap, name); int r = uv_os_unsetenv(name); // Must do this before ELOG, log.c may call os_setenv. uv_mutex_unlock(&mutex); |