1 |
commit: 7a07798e6a7ce183ed53e6ad19d0c3a7205aae52 |
2 |
Author: Mike Frysinger <vapier <AT> gentoo <DOT> org> |
3 |
AuthorDate: Fri Nov 27 23:19:05 2015 +0000 |
4 |
Commit: Mike Frysinger <vapier <AT> gentoo <DOT> org> |
5 |
CommitDate: Fri Nov 27 23:19:05 2015 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=7a07798e |
7 |
|
8 |
main: optimize portdir setup slightly |
9 |
|
10 |
libq/xarray.c | 6 ++++-- |
11 |
main.c | 9 +++------ |
12 |
2 files changed, 7 insertions(+), 8 deletions(-) |
13 |
|
14 |
diff --git a/libq/xarray.c b/libq/xarray.c |
15 |
index 56f04da..339d759 100644 |
16 |
--- a/libq/xarray.c |
17 |
+++ b/libq/xarray.c |
18 |
@@ -24,11 +24,13 @@ typedef struct { |
19 |
#define array_cnt(arr) (arr)->num |
20 |
#define DECLARE_ARRAY(arr) array_t _##arr = array_init_decl, *arr = &_##arr |
21 |
|
22 |
-static void xarraypush(array_t *arr, const void *ele, size_t ele_len) |
23 |
+static void *xarraypush(array_t *arr, const void *ele, size_t ele_len) |
24 |
{ |
25 |
+ void *nele; |
26 |
size_t n = arr->num++; |
27 |
arr->eles = xrealloc_array(arr->eles, arr->num, sizeof(ele)); |
28 |
- arr->eles[n] = xmemdup(ele, ele_len); |
29 |
+ arr->eles[n] = nele = xmemdup(ele, ele_len); |
30 |
+ return nele; |
31 |
} |
32 |
#define xarraypush_str(arr, ele) xarraypush(arr, ele, strlen(ele) + 1 /*NUL*/) |
33 |
|
34 |
|
35 |
diff --git a/main.c b/main.c |
36 |
index 42a3f26..9361b98 100644 |
37 |
--- a/main.c |
38 |
+++ b/main.c |
39 |
@@ -445,12 +445,9 @@ static void read_one_repos_conf(const char *repos_conf) |
40 |
xasprintf(&conf, "%s:location", repo); |
41 |
path = iniparser_getstring(dict, conf, NULL); |
42 |
if (path) { |
43 |
- if (main_repo && !strcmp(repo, main_repo)) { |
44 |
- free(portdir); |
45 |
- portdir = xstrdup(path); |
46 |
- } |
47 |
- |
48 |
- xarraypush_str(overlays, path); |
49 |
+ void *ele = xarraypush_str(overlays, path); |
50 |
+ if (main_repo && !strcmp(repo, main_repo)) |
51 |
+ portdir = ele; |
52 |
} |
53 |
free(conf); |
54 |
} |