From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) by finch.gentoo.org (Postfix) with ESMTP id 406AE1388C1 for ; Mon, 22 Feb 2016 20:37:25 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 5B21021C017; Mon, 22 Feb 2016 20:37:24 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id B536821C014 for ; Mon, 22 Feb 2016 20:37:23 +0000 (UTC) Received: from oystercatcher.gentoo.org (unknown [IPv6:2a01:4f8:202:4333:225:90ff:fed9:fc84]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id CE7C6340B37 for ; Mon, 22 Feb 2016 20:37:22 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id CBACB14CD for ; Mon, 22 Feb 2016 20:37:18 +0000 (UTC) From: "Mike Frysinger" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Mike Frysinger" Message-ID: <1456162901.54a6bc76557216d67a21673b8f0e479efae21a79.vapier@gentoo> Subject: [gentoo-commits] proj/portage-utils:master commit in: / X-VCS-Repository: proj/portage-utils X-VCS-Files: qsize.c X-VCS-Directories: / X-VCS-Committer: vapier X-VCS-Committer-Name: Mike Frysinger X-VCS-Revision: 54a6bc76557216d67a21673b8f0e479efae21a79 X-VCS-Branch: master Date: Mon, 22 Feb 2016 20:37:18 +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-Archives-Salt: 3edd17d7-59e2-464b-86f1-c24818033bdb X-Archives-Hash: 009625da6919823dfd247ccd5454a557 commit: 54a6bc76557216d67a21673b8f0e479efae21a79 Author: Mike Frysinger gentoo org> AuthorDate: Mon Feb 22 17:41:41 2016 +0000 Commit: Mike Frysinger gentoo org> CommitDate: Mon Feb 22 17:41:41 2016 +0000 URL: https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=54a6bc76 qcheck: precompile ignore regexes This should speed things up a bit. qsize.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/qsize.c b/qsize.c index 7a2503a..3a11842 100644 --- a/qsize.c +++ b/qsize.c @@ -38,7 +38,7 @@ int qsize_main(int argc, char **argv) q_vdb_ctx *ctx; q_vdb_cat_ctx *cat_ctx; q_vdb_pkg_ctx *pkg_ctx; - int i; + size_t i; char search_all = 0; struct stat st; char fs_size = 0, summary = 0, summary_only = 0; @@ -50,7 +50,7 @@ int qsize_main(int argc, char **argv) size_t buflen; char *buf; char filename[_Q_PATH_MAX], *filename_root; - queue *ignore_regexp = NULL; + DECLARE_ARRAY(ignore_regexp); while ((i = GETOPT_LONG(QSIZE, qsize, "")) != -1) { switch (i) { @@ -62,7 +62,12 @@ int qsize_main(int argc, char **argv) case 'm': disp_units = MEGABYTE; str_disp_units = "MiB"; break; case 'k': disp_units = KILOBYTE; str_disp_units = "KiB"; break; case 'b': disp_units = 1; str_disp_units = "bytes"; break; - case 'i': ignore_regexp = add_set(optarg, ignore_regexp); break; + case 'i': { + regex_t regex; + xregcomp(®ex, optarg, REG_EXTENDED|REG_NOSUB); + xarraypush(ignore_regexp, ®ex, sizeof(regex)); + break; + } } } if ((argc == optind) && !search_all) @@ -105,19 +110,18 @@ int qsize_main(int argc, char **argv) num_ignored = num_files = num_nonfiles = num_bytes = 0; while (getline(&buf, &buflen, fp) != -1) { contents_entry *e; - queue *ll; + regex_t *regex; int ok = 0; e = contents_parse_line(buf); if (!e) continue; - for (ll = ignore_regexp; ll != NULL; ll = ll->next) { - if (rematch(ll->name, e->name, REG_EXTENDED) == 0) { + array_for_each(ignore_regexp, i, regex) + if (!regexec(regex, buf, 0, NULL, 0)) { num_ignored += 1; ok = 1; } - } if (ok) continue; @@ -174,7 +178,7 @@ int qsize_main(int argc, char **argv) decimal_point, (unsigned long)(((num_all_bytes%MEGABYTE)*1000)/MEGABYTE)); } - free_sets(ignore_regexp); + xarrayfree(ignore_regexp); return EXIT_SUCCESS; }