From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id 53D50138334 for ; Wed, 19 Jun 2019 10:44:21 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 76CBBE0931; Wed, 19 Jun 2019 10:44:20 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 44A75E08F1 for ; Wed, 19 Jun 2019 10:44:20 +0000 (UTC) Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id E09E0346497 for ; Wed, 19 Jun 2019 10:44:18 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 0370E614 for ; Wed, 19 Jun 2019 10:44:17 +0000 (UTC) From: "Fabian Groffen" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Fabian Groffen" Message-ID: <1560940989.1089b8baedcd1d6d7aa41e8f5f81938660079e01.grobian@gentoo> Subject: [gentoo-commits] proj/portage-utils:master commit in: libq/, / X-VCS-Repository: proj/portage-utils X-VCS-Files: TODO.md libq/set.c qcheck.c qkeyword.c qmerge.c qpkg.c X-VCS-Directories: libq/ / X-VCS-Committer: grobian X-VCS-Committer-Name: Fabian Groffen X-VCS-Revision: 1089b8baedcd1d6d7aa41e8f5f81938660079e01 X-VCS-Branch: master Date: Wed, 19 Jun 2019 10:44:17 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-Archives-Salt: 8862b82c-4538-4680-98ee-dc0fc43d9b72 X-Archives-Hash: 74441e51105459d2e69e6a9800cc90e0 commit: 1089b8baedcd1d6d7aa41e8f5f81938660079e01 Author: Fabian Groffen gentoo org> AuthorDate: Wed Jun 19 10:43:09 2019 +0000 Commit: Fabian Groffen gentoo 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 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:
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 #include -#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;