commit: 1089b8baedcd1d6d7aa41e8f5f81938660079e01
Author: Fabian Groffen <grobian <AT> gentoo <DOT> org>
AuthorDate: Wed Jun 19 10:43:09 2019 +0000
Commit: Fabian Groffen <grobian <AT> gentoo <DOT> org>
CommitDate: Wed Jun 19 10:43:09 2019 +0000
URL: https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=1089b8ba
libq/set: drop rmspace for all inputs
Most of the times, rmspace is unnecessary, and doing so, requires a
mutable copy of the data. If the callers call rmspace when necessary,
set can be a bit more efficient.
Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org>
TODO.md | 3 ---
libq/set.c | 17 ++++-------------
qcheck.c | 1 -
qkeyword.c | 7 ++++---
qmerge.c | 14 +++++++++-----
qpkg.c | 6 ++----
6 files changed, 19 insertions(+), 29 deletions(-)
diff --git a/TODO.md b/TODO.md
index f9a713b..a319492 100644
--- a/TODO.md
+++ b/TODO.md
@@ -6,9 +6,6 @@
- -r (-R ?) regexp foo.\*
- make default -e for apps like quse/qdepends?
-- remove odd rmspace for each string in libq/set.c (allows a lot less
- malloc/frees)
-
- make set.c to array (xarray) instead of C-array (list)
- env vars only get expanded once, so this fails:<br>
diff --git a/libq/set.c b/libq/set.c
index de60410..f2c9394 100644
--- a/libq/set.c
+++ b/libq/set.c
@@ -15,7 +15,6 @@
#include <string.h>
#include <xalloc.h>
-#include "rmspace.h"
#include "set.h"
static unsigned int
@@ -47,7 +46,6 @@ add_set(const char *name, set *q)
ll->next = NULL;
ll->name = xstrdup(name);
- rmspace(ll->name);
ll->hash = fnv1a32(ll->name);
pos = ll->hash % _SET_HASH_SIZE;
@@ -77,7 +75,6 @@ add_set_unique(const char *name, set *q, bool *unique)
if (q == NULL)
q = create_set();
- rmspace(mname);
hash = fnv1a32(mname);
pos = hash % _SET_HASH_SIZE;
@@ -116,27 +113,24 @@ add_set_unique(const char *name, set *q, bool *unique)
bool
contains_set(char *s, set *q)
{
- char *mname = xstrdup(s);
unsigned int hash;
int pos;
elem *w;
bool found;
- rmspace(mname);
- hash = fnv1a32(mname);
+ hash = fnv1a32(s);
pos = hash % _SET_HASH_SIZE;
found = false;
if (q->buckets[pos] != NULL) {
for (w = q->buckets[pos]; w != NULL; w = w->next) {
- if (w->hash == hash && strcmp(w->name, mname) == 0) {
+ if (w->hash == hash && strcmp(w->name, s) == 0) {
found = true;
break;
}
}
}
- free(mname);
return found;
}
@@ -144,22 +138,19 @@ contains_set(char *s, set *q)
set *
del_set(char *s, set *q, bool *removed)
{
- char *mname = xstrdup(s);
unsigned int hash;
int pos;
elem *ll;
elem *w;
- rmspace(mname);
- hash = fnv1a32(mname);
+ hash = fnv1a32(s);
pos = hash % _SET_HASH_SIZE;
*removed = false;
if (q->buckets[pos] != NULL) {
ll = NULL;
for (w = q->buckets[pos]; w != NULL; ll = w, w = w->next) {
- if (w->hash == hash && strcmp(w->name, mname) == 0) {
- free(mname);
+ if (w->hash == hash && strcmp(w->name, s) == 0) {
if (ll == NULL) {
q->buckets[pos] = w->next;
} else {
diff --git a/qcheck.c b/qcheck.c
index 8eb1f08..97070f2 100644
--- a/qcheck.c
+++ b/qcheck.c
@@ -19,7 +19,6 @@
#include "contents.h"
#include "md5_sha1_sum.h"
#include "prelink.h"
-#include "set.h"
#include "tree.h"
#include "xarray.h"
#include "xasprintf.h"
diff --git a/qkeyword.c b/qkeyword.c
index fda9b83..9c7187e 100644
--- a/qkeyword.c
+++ b/qkeyword.c
@@ -666,10 +666,11 @@ qkeyword_load_arches(const char *overlay)
buf = NULL;
while ((linelen = getline(&buf, &buflen, fp)) >= 0) {
- rmspace_len(buf, (size_t)linelen);
-
- if ((s = strchr(buf, '#')) != NULL)
+ if ((s = strchr(buf, '#')) != NULL) {
*s = '\0';
+ linelen = s - buf;
+ }
+ rmspace_len(buf, (size_t)linelen);
if (buf[0] == '\0')
continue;
diff --git a/qmerge.c b/qmerge.c
index 47a6e9b..cb4342c 100644
--- a/qmerge.c
+++ b/qmerge.c
@@ -2289,7 +2289,7 @@ parse_packages(set *todo)
}
static set *
-qmerge_add_set_file(const char *dir, const char *file, set *q)
+qmerge_add_set_file(const char *pfx, const char *dir, const char *file, set *q)
{
FILE *fp;
int linelen;
@@ -2297,7 +2297,7 @@ qmerge_add_set_file(const char *dir, const char *file,
set *q)
char *buf, *fname;
/* Find the file to read */
- xasprintf(&fname, "%s%s/%s", portroot, dir, file);
+ xasprintf(&fname, "%s%s%s/%s", portroot, pfx, dir, file);
if ((fp = fopen(fname, "r")) == NULL) {
warnp("unable to read set file %s", fname);
@@ -2348,15 +2348,19 @@ static set *
qmerge_add_set(char *buf, set *q)
{
if (strcmp(buf, "world") == 0)
- return qmerge_add_set_file("/var/lib/portage", "world", q);
+ return qmerge_add_set_file(CONFIG_EPREFIX, "/var/lib/portage",
+ "world", q);
else if (strcmp(buf, "all") == 0)
return tree_get_vdb_atoms(portroot, portvdb, 0);
else if (strcmp(buf, "system") == 0)
return q_profile_walk("packages", qmerge_add_set_system, q);
else if (buf[0] == '@')
- return qmerge_add_set_file("/etc/portage", buf+1, q);
- else
+ /* TODO: use configroot */
+ return qmerge_add_set_file(CONFIG_EPREFIX, "/etc/portage",
buf+1, q);
+ else {
+ rmspace(buf);
return add_set(buf, q);
+ }
}
static int
diff --git a/qpkg.c b/qpkg.c
index 26c14d1..4063af2 100644
--- a/qpkg.c
+++ b/qpkg.c
@@ -127,14 +127,12 @@ static int
qpkg_cb(tree_pkg_ctx *pkg_ctx, void *priv)
{
set *vdb = (set *)priv;
- depend_atom *atom;
char buf[_Q_PATH_MAX];
- snprintf(buf, sizeof(buf), "%s/%s", pkg_ctx->cat_ctx->name,
pkg_ctx->name);
- atom = atom_explode(buf);
- if (atom == NULL)
+ if (tree_get_atom(pkg_ctx, false) == NULL)
return 0;
+ snprintf(buf, sizeof(buf), "%s/%s", pkg_ctx->cat_ctx->name,
pkg_ctx->name);
vdb = add_set(buf, vdb);
return 1;