pkgsrc-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[pkgsrc/pkg_install-renovation]: pkgsrc/pkgtools/pkg_install/files Add quick_...
details: https://anonhg.NetBSD.org/pkgsrc/rev/2ff40aa5761f
branches: pkg_install-renovation
changeset: 541537:2ff40aa5761f
user: joerg <joerg%pkgsrc.org@localhost>
date: Mon May 12 12:12:07 2008 +0000
description:
Add quick_pkg_match to decide whether a pattern can match a package at
all. Use it to speed up pkg_match and the audit-history backend.
This improves ``pkg_admin audit'' from 1.333s to 0.098s and
``pkg_admin audit php libpng'' from 0.034s to 0.029s on my laptop.
diffstat:
pkgtools/pkg_install/files/admin/audit.c | 6 ++++--
pkgtools/pkg_install/files/lib/lib.h | 3 ++-
pkgtools/pkg_install/files/lib/opattern.c | 28 ++++++++++++++++++++++++++--
3 files changed, 32 insertions(+), 5 deletions(-)
diffs (98 lines):
diff -r 25b7b70e81c6 -r 2ff40aa5761f pkgtools/pkg_install/files/admin/audit.c
--- a/pkgtools/pkg_install/files/admin/audit.c Sun May 11 20:20:37 2008 +0000
+++ b/pkgtools/pkg_install/files/admin/audit.c Mon May 12 12:12:07 2008 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: audit.c,v 1.8 2008/04/16 00:53:06 joerg Exp $ */
+/* $NetBSD: audit.c,v 1.8.2.1 2008/05/12 12:12:07 joerg Exp $ */
#if HAVE_CONFIG_H
#include "config.h"
@@ -8,7 +8,7 @@
#include <sys/cdefs.h>
#endif
#ifndef lint
-__RCSID("$NetBSD: audit.c,v 1.8 2008/04/16 00:53:06 joerg Exp $");
+__RCSID("$NetBSD: audit.c,v 1.8.2.1 2008/05/12 12:12:07 joerg Exp $");
#endif
/*-
@@ -483,6 +483,8 @@
size_t i;
for (i = 0; i < pv->entries; ++i) {
+ if (!quick_pkg_match(pv->vulnerability[i], pkg))
+ continue;
if (strcmp("eol", pv->classification[i]) == 0)
continue;
if (check_pkg_history1(pkg, pv->vulnerability[i]) == 0)
diff -r 25b7b70e81c6 -r 2ff40aa5761f pkgtools/pkg_install/files/lib/lib.h
--- a/pkgtools/pkg_install/files/lib/lib.h Sun May 11 20:20:37 2008 +0000
+++ b/pkgtools/pkg_install/files/lib/lib.h Mon May 12 12:12:07 2008 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lib.h,v 1.42.2.3 2008/05/11 20:20:38 joerg Exp $ */
+/* $NetBSD: lib.h,v 1.42.2.4 2008/05/12 12:12:07 joerg Exp $ */
/* from FreeBSD Id: lib.h,v 1.25 1997/10/08 07:48:03 charnier Exp */
@@ -284,6 +284,7 @@
int pkg_match(const char *, const char *);
int pkg_order(const char *, const char *, const char *);
int ispkgpattern(const char *);
+int quick_pkg_match(const char *, const char *);
/* Iterator functions */
int iterate_pkg_generic_src(int (*)(const char *, void *), void *,
diff -r 25b7b70e81c6 -r 2ff40aa5761f pkgtools/pkg_install/files/lib/opattern.c
--- a/pkgtools/pkg_install/files/lib/opattern.c Sun May 11 20:20:37 2008 +0000
+++ b/pkgtools/pkg_install/files/lib/opattern.c Mon May 12 12:12:07 2008 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: opattern.c,v 1.4 2007/10/14 23:24:24 rillig Exp $ */
+/* $NetBSD: opattern.c,v 1.4.6.1 2008/05/12 12:12:07 joerg Exp $ */
#if HAVE_CONFIG_H
#include "config.h"
@@ -11,7 +11,7 @@
#if 0
static const char *rcsid = "Id: str.c,v 1.5 1997/10/08 07:48:21 charnier Exp";
#else
-__RCSID("$NetBSD: opattern.c,v 1.4 2007/10/14 23:24:24 rillig Exp $");
+__RCSID("$NetBSD: opattern.c,v 1.4.6.1 2008/05/12 12:12:07 joerg Exp $");
#endif
#endif
@@ -119,11 +119,35 @@
}
/*
+ * Performs a fast check if pattern can ever match pkg.
+ * Returns 1 if a match is possible and 0 otherwise.
+ */
+int
+quick_pkg_match(const char *pattern, const char *pkg)
+{
+#define simple(x) (isalnum((unsigned char)(x)) || (x) == '-')
+ if (!simple(pattern[0]))
+ return 1;
+ if (pattern[0] != pkg[0])
+ return 0;
+
+ if (!simple(pattern[1]))
+ return 1;
+ if (pattern[1] != pkg[1])
+ return 0;
+ return 1;
+#undef simple
+}
+
+/*
* Match pkg against pattern, return 1 if matching, 0 else
*/
int
pkg_match(const char *pattern, const char *pkg)
{
+ if (!quick_pkg_match(pattern, pkg))
+ return 0;
+
if (strchr(pattern, '{') != (char *) NULL) {
/* emulate csh-type alternates */
return alternate_match(pattern, pkg);
Home |
Main Index |
Thread Index |
Old Index