1 |
commit: 2977f24478a673ff869bb6d26bf69b90b099deb5 |
2 |
Author: Fabian Groffen <grobian <AT> gentoo <DOT> org> |
3 |
AuthorDate: Fri May 10 15:31:00 2019 +0000 |
4 |
Commit: Fabian Groffen <grobian <AT> gentoo <DOT> org> |
5 |
CommitDate: Fri May 10 15:31:00 2019 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=2977f244 |
7 |
|
8 |
qkeyword: optimise away redundant atom_explode calls |
9 |
|
10 |
With some help from libq/tree now doing the sorting right (and |
11 |
contructing an atom exactly once for each package) we can avoid |
12 |
exploding atoms and greatly benefit in performance. On my setup I've |
13 |
seen timings half or even more. |
14 |
|
15 |
Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org> |
16 |
|
17 |
TODO.md | 4 ---- |
18 |
qkeyword.c | 47 +++++------------------------------------------ |
19 |
2 files changed, 5 insertions(+), 46 deletions(-) |
20 |
|
21 |
diff --git a/TODO.md b/TODO.md |
22 |
index ec5f843..768c435 100644 |
23 |
--- a/TODO.md |
24 |
+++ b/TODO.md |
25 |
@@ -93,8 +93,4 @@ |
26 |
- read VDB on -v to print details about current USE-flag status, bug #656550 |
27 |
|
28 |
# qkeyword |
29 |
-- avoid multiple atom\_explode in path traversal |
30 |
- * during qkeyword\_vercmp |
31 |
- * during qkeyword\_results\_cb |
32 |
- * in libq/cache\_read\_metadata |
33 |
- drop -c argument? it can be fully expressed using -p cat/ |
34 |
|
35 |
diff --git a/qkeyword.c b/qkeyword.c |
36 |
index b9792af..fda9b83 100644 |
37 |
--- a/qkeyword.c |
38 |
+++ b/qkeyword.c |
39 |
@@ -191,28 +191,6 @@ read_keywords(char *s, int *keywords) |
40 |
return 0; |
41 |
} |
42 |
|
43 |
-/* |
44 |
- * Compare 2 struct dirent d_name strings based with atom_compare_str(). |
45 |
- * Used with dirscan() to sort ebuild filenames by version, reversed. |
46 |
- * |
47 |
- * IN: |
48 |
- * 2 (const struct dirent **) with d_name filled in |
49 |
- * OUT: |
50 |
- * -1 (NEWER) |
51 |
- * 1 (OLDER) |
52 |
- * 0 (SAME) |
53 |
- */ |
54 |
-static int |
55 |
-qkeyword_vercmp(const struct dirent **x, const struct dirent **y) |
56 |
-{ |
57 |
- switch (atom_compare_str((*x)->d_name, (*y)->d_name)) { |
58 |
- case EQUAL: return 0; |
59 |
- case NEWER: return -1; |
60 |
- case OLDER: return 1; |
61 |
- default: return strcmp((*x)->d_name, (*y)->d_name); |
62 |
- } |
63 |
-} |
64 |
- |
65 |
static int |
66 |
qkeyword_imlate(tree_pkg_ctx *pkg_ctx, void *priv) |
67 |
{ |
68 |
@@ -496,7 +474,7 @@ qkeyword_stats(tree_pkg_ctx *pkg_ctx, void *priv) |
69 |
numcat++; |
70 |
lastcat = pkg_ctx->cat_ctx->name; |
71 |
|
72 |
- atom = atom_explode(pkg_ctx->name); |
73 |
+ atom = tree_get_atom(pkg_ctx, false); |
74 |
if (atom && strcmp(lastpkg, atom->PN) != 0) { |
75 |
for (a = 0; a < archlist_count; a++) { |
76 |
switch (current_package_keywords[a]) { |
77 |
@@ -515,7 +493,6 @@ qkeyword_stats(tree_pkg_ctx *pkg_ctx, void *priv) |
78 |
memset(current_package_keywords, 0, |
79 |
archlist_count * sizeof(*current_package_keywords)); |
80 |
} |
81 |
- atom_implode(atom); |
82 |
|
83 |
numebld++; |
84 |
|
85 |
@@ -617,25 +594,17 @@ qkeyword_results_cb(tree_pkg_ctx *pkg_ctx, void *priv) |
86 |
struct elist *emailw; |
87 |
int ret; |
88 |
|
89 |
- snprintf(buf, sizeof(buf), "%s/%s", |
90 |
- pkg_ctx->cat_ctx->name, pkg_ctx->name); |
91 |
- patom = atom_explode(buf); |
92 |
+ patom = tree_get_atom(pkg_ctx, false); |
93 |
if (patom == NULL) |
94 |
return EXIT_FAILURE; |
95 |
|
96 |
if (data->qatom != NULL && |
97 |
atom_compare(patom, data->qatom) != EQUAL) |
98 |
- { |
99 |
- atom_implode(patom); |
100 |
return EXIT_FAILURE; |
101 |
- } |
102 |
|
103 |
if (data->lastatom != NULL && |
104 |
atom_compare(data->lastatom, patom) != NOT_EQUAL) |
105 |
- { |
106 |
- atom_implode(patom); |
107 |
return EXIT_SUCCESS; |
108 |
- } |
109 |
|
110 |
if (data->qmaint != NULL) { |
111 |
metadata = tree_pkg_metadata(pkg_ctx); |
112 |
@@ -657,16 +626,13 @@ qkeyword_results_cb(tree_pkg_ctx *pkg_ctx, void *priv) |
113 |
|
114 |
keywords = data->keywordsbuf; |
115 |
meta = tree_pkg_read(pkg_ctx); |
116 |
- if (meta == NULL) { |
117 |
- atom_implode(patom); |
118 |
+ if (meta == NULL) |
119 |
return EXIT_FAILURE; |
120 |
- } |
121 |
|
122 |
if (read_keywords(meta->KEYWORDS, keywords) < 0) { |
123 |
if (verbose) |
124 |
warn("Failed to read keywords for %s%s/%s%s%s", |
125 |
BOLD, pkg_ctx->cat_ctx->name, BLUE, pkg_ctx->name, NORM); |
126 |
- atom_implode(patom); |
127 |
return EXIT_FAILURE; |
128 |
} |
129 |
|
130 |
@@ -678,9 +644,7 @@ qkeyword_results_cb(tree_pkg_ctx *pkg_ctx, void *priv) |
131 |
patom->PVR = patom->PN; |
132 |
patom->PR_int = 0; |
133 |
data->lastatom = patom; |
134 |
- patom = NULL; |
135 |
- } else { |
136 |
- atom_implode(patom); |
137 |
+ pkg_ctx->atom = NULL; /* take tree's atom */ |
138 |
} |
139 |
|
140 |
return EXIT_SUCCESS; |
141 |
@@ -759,8 +723,7 @@ qkeyword_traverse(tree_pkg_cb func, void *priv) |
142 |
array_for_each(overlays, n, overlay) { |
143 |
tree_ctx *t = tree_open(portroot, overlay); |
144 |
if (t != NULL) { |
145 |
- ret |= tree_foreach_pkg(t, qkeyword_results_cb, priv, |
146 |
- NULL, true, NULL, qkeyword_vercmp); |
147 |
+ ret |= tree_foreach_pkg_sorted(t, qkeyword_results_cb, priv); |
148 |
tree_close(t); |
149 |
} |
150 |
} |