commit: 7a07798e6a7ce183ed53e6ad19d0c3a7205aae52
Author: Mike Frysinger <vapier <AT> gentoo <DOT> org>
AuthorDate: Fri Nov 27 23:19:05 2015 +0000
Commit: Mike Frysinger <vapier <AT> gentoo <DOT> org>
CommitDate: Fri Nov 27 23:19:05 2015 +0000
URL: https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=7a07798e
main: optimize portdir setup slightly
libq/xarray.c | 6 ++++--
main.c | 9 +++------
2 files changed, 7 insertions(+), 8 deletions(-)
diff --git a/libq/xarray.c b/libq/xarray.c
index 56f04da..339d759 100644
--- a/libq/xarray.c
+++ b/libq/xarray.c
@@ -24,11 +24,13 @@ typedef struct {
#define array_cnt(arr) (arr)->num
#define DECLARE_ARRAY(arr) array_t _##arr = array_init_decl, *arr = &_##arr
-static void xarraypush(array_t *arr, const void *ele, size_t ele_len)
+static void *xarraypush(array_t *arr, const void *ele, size_t ele_len)
{
+ void *nele;
size_t n = arr->num++;
arr->eles = xrealloc_array(arr->eles, arr->num, sizeof(ele));
- arr->eles[n] = xmemdup(ele, ele_len);
+ arr->eles[n] = nele = xmemdup(ele, ele_len);
+ return nele;
}
#define xarraypush_str(arr, ele) xarraypush(arr, ele, strlen(ele) + 1 /*NUL*/)
diff --git a/main.c b/main.c
index 42a3f26..9361b98 100644
--- a/main.c
+++ b/main.c
@@ -445,12 +445,9 @@ static void read_one_repos_conf(const char *repos_conf)
xasprintf(&conf, "%s:location", repo);
path = iniparser_getstring(dict, conf, NULL);
if (path) {
- if (main_repo && !strcmp(repo, main_repo)) {
- free(portdir);
- portdir = xstrdup(path);
- }
-
- xarraypush_str(overlays, path);
+ void *ele = xarraypush_str(overlays, path);
+ if (main_repo && !strcmp(repo, main_repo))
+ portdir = ele;
}
free(conf);
}