Skip to content

Commit 1b70868

Browse files
committed
config_cache: cleanup config map lookup
1 parent f52f593 commit 1b70868

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/config_cache.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,18 +111,21 @@ int git_config__configmap_lookup(int *out, git_config *config, git_configmap_ite
111111

112112
int git_repository__configmap_lookup(int *out, git_repository *repo, git_configmap_item item)
113113
{
114-
*out = (int)(intptr_t)git_atomic_load(repo->configmap_cache[(int)item]);
114+
intptr_t value = (intptr_t)git_atomic_load(repo->configmap_cache[(int)item]);
115115

116-
if (*out == GIT_CONFIGMAP_NOT_CACHED) {
117-
int error;
118-
int oldval = GIT_CONFIGMAP_NOT_CACHED;
116+
*out = (int)value;
117+
118+
if (value == GIT_CONFIGMAP_NOT_CACHED) {
119119
git_config *config;
120+
intptr_t oldval = value;
121+
int error;
120122

121123
if ((error = git_repository_config__weakptr(&config, repo)) < 0 ||
122124
(error = git_config__configmap_lookup(out, config, item)) < 0)
123125
return error;
124126

125-
git_atomic_compare_and_swap(&repo->configmap_cache[(int)item], &oldval, out);
127+
value = *out;
128+
git_atomic_compare_and_swap(&repo->configmap_cache[(int)item], (void *)oldval, (void *)value);
126129
}
127130

128131
return 0;

0 commit comments

Comments
 (0)