pkgsrc-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[pkgsrc/trunk]: pkgsrc/pkgtools pbulk-base-0.44: Fix hash function to actuall...



details:   https://anonhg.NetBSD.org/pkgsrc/rev/622ba9223130
branches:  trunk
changeset: 595997:622ba9223130
user:      joerg <joerg%pkgsrc.org@localhost>
date:      Sun Nov 27 19:53:30 2011 +0000

description:
pbulk-base-0.44: Fix hash function to actually do proper hashing.
Do some further tweaking to improve matching by storing string size.
While here, add the necessary .WAIT to allow parallel builds.

diffstat:

 pkgtools/pbulk-base/Makefile               |   4 +-
 pkgtools/pbulk/Makefile.common             |   3 +-
 pkgtools/pbulk/files/pbulk/Makefile        |   4 +-
 pkgtools/pbulk/files/pbulk/pbuild/jobs.c   |  50 ++++++++++++++++++------------
 pkgtools/pbulk/files/pbulk/pbuild/pbuild.h |   3 +-
 5 files changed, 37 insertions(+), 27 deletions(-)

diffs (184 lines):

diff -r 1b36cf5eb0ac -r 622ba9223130 pkgtools/pbulk-base/Makefile
--- a/pkgtools/pbulk-base/Makefile      Sun Nov 27 19:50:23 2011 +0000
+++ b/pkgtools/pbulk-base/Makefile      Sun Nov 27 19:53:30 2011 +0000
@@ -1,6 +1,6 @@
-# $NetBSD: Makefile,v 1.6 2011/09/21 11:55:15 joerg Exp $
+# $NetBSD: Makefile,v 1.7 2011/11/27 19:53:30 joerg Exp $
 
-DISTNAME=      pbulk-base-0.43
+DISTNAME=      pbulk-base-0.44
 COMMENT=       Core components of the modular bulk build framework
 
 PKG_DESTDIR_SUPPORT=   user-destdir
diff -r 1b36cf5eb0ac -r 622ba9223130 pkgtools/pbulk/Makefile.common
--- a/pkgtools/pbulk/Makefile.common    Sun Nov 27 19:50:23 2011 +0000
+++ b/pkgtools/pbulk/Makefile.common    Sun Nov 27 19:53:30 2011 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile.common,v 1.1 2009/06/08 15:37:50 joerg Exp $
+# $NetBSD: Makefile.common,v 1.2 2011/11/27 19:53:30 joerg Exp $
 
 CATEGORIES=    pkgtools
 MASTER_SITES=  # empty
@@ -10,4 +10,3 @@
 FILESDIR=      ${.CURDIR}/../../pkgtools/pbulk/files
 
 WRKSRC=                ${WRKDIR}/pbulk
-MAKE_JOBS_SAFE=        no
diff -r 1b36cf5eb0ac -r 622ba9223130 pkgtools/pbulk/files/pbulk/Makefile
--- a/pkgtools/pbulk/files/pbulk/Makefile       Sun Nov 27 19:50:23 2011 +0000
+++ b/pkgtools/pbulk/files/pbulk/Makefile       Sun Nov 27 19:53:30 2011 +0000
@@ -1,5 +1,5 @@
-# $NetBSD: Makefile,v 1.1.1.1 2007/06/19 19:49:55 joerg Exp $
+# $NetBSD: Makefile,v 1.2 2011/11/27 19:53:30 joerg Exp $
 
-SUBDIR=        lib presolve pscan pbuild scripts
+SUBDIR=        lib .WAIT presolve pscan pbuild scripts
 
 .include <bsd.subdir.mk>
diff -r 1b36cf5eb0ac -r 622ba9223130 pkgtools/pbulk/files/pbulk/pbuild/jobs.c
--- a/pkgtools/pbulk/files/pbulk/pbuild/jobs.c  Sun Nov 27 19:50:23 2011 +0000
+++ b/pkgtools/pbulk/files/pbulk/pbuild/jobs.c  Sun Nov 27 19:53:30 2011 +0000
@@ -1,7 +1,7 @@
-/* $NetBSD: jobs.c,v 1.12 2010/05/05 00:07:07 joerg Exp $ */
+/* $NetBSD: jobs.c,v 1.13 2011/11/27 19:53:30 joerg Exp $ */
 
 /*-
- * Copyright (c) 2007, 2009 Joerg Sonnenberger <joerg%NetBSD.org@localhost>.
+ * Copyright (c) 2007, 2009, 2011 Joerg Sonnenberger <joerg%NetBSD.org@localhost>.
  * All rights reserved.
  *
  * This code was developed as part of Google's Summer of Code 2007 program.
@@ -56,7 +56,7 @@
 
 static void build_tree(void);
 static void mark_initial(void);
-static struct buildhash *get_hash_chain(const char *);
+static struct buildhash *get_hash_chain(const char *, size_t);
 static void hash_entries(void);
 static void add_to_build_list(struct build_job *);
 
@@ -109,22 +109,24 @@
        return NULL;
 }
 
-static char *
-pkgname_dup(const char *line)
+static int
+pkgname_dup(struct build_job *job, const char *line)
 {
        const char *pkgname;
        char *pkgname_end;
        size_t pkgname_len;
 
        if (strncmp(line, "PKGNAME=", 8) != 0)
-               return NULL;
+               return 0;
        pkgname = line + 8;
        pkgname_end = strchr(pkgname, '\n');
        pkgname_len = pkgname_end - pkgname;
        if (pkgname_end == NULL || pkgname_len < 4 ||
            strcspn(pkgname, " \t\n") != pkgname_len)
-               return NULL;
-       return xstrndup(pkgname, pkgname_len);
+               return 0;
+       job->pkgname = xstrndup(pkgname, pkgname_len);
+       job->pkgname_len = pkgname_len;
+       return 1;
 }
 
 static const char *
@@ -215,7 +217,7 @@
        }
 
        input_iter = input;
-       while ((jobs[len_jobs].pkgname = pkgname_dup(input_iter)) != NULL) {
+       while (pkgname_dup(&jobs[len_jobs], input_iter)) {
                jobs[len_jobs].begin = input_iter;
                jobs[len_jobs].end = pbulk_item_end(input_iter);
                jobs[len_jobs].state = JOB_INIT;
@@ -262,9 +264,9 @@
 
        while (*input_iter != '\0') {
                len = strcspn(input_iter, "\n");
-               SLIST_FOREACH(iter, get_hash_chain(input_iter), hash_link) {
-                       if (strncmp(iter->pkgname, input_iter, len) == 0 &&
-                           iter->pkgname[len] == '\0')
+               SLIST_FOREACH(iter, get_hash_chain(input_iter, len), hash_link) {
+                       if (iter->pkgname_len == len &&
+                           strncmp(iter->pkgname, input_iter, len) == 0)
                                break;
                }
                if (iter == NULL)
@@ -274,7 +276,7 @@
 
                input_iter = strchr(input_iter, '\n');
                if (input_iter == NULL)
-                       errx(1, "Invalid input");               
+                       errx(1, "Invalid input");
                ++input_iter;
        }
        free(input);
@@ -340,9 +342,9 @@
                depends += strspn(depends, " \t");
 
                while ((len = strcspn(depends, " \t\n")) != 0) {
-                       SLIST_FOREACH(iter, get_hash_chain(depends), hash_link) {
-                               if (strncmp(iter->pkgname, depends, len) == 0 &&
-                                   iter->pkgname[len] == '\0')
+                       SLIST_FOREACH(iter, get_hash_chain(depends, len), hash_link) {
+                               if (iter->pkgname_len == len &&
+                                   strncmp(iter->pkgname, depends, len) == 0)
                                        break;
                        }
                        if (iter == NULL)
@@ -530,7 +532,15 @@
 }
 
 #define        HASH_SIZE 4096
-#define        HASH_ITEM(x) (((unsigned char)(x)[0] + (unsigned char)(x)[1] * 257 + (unsigned char)(x)[1] * 65537) & (HASH_SIZE - 1))
+
+static size_t
+hash_item(const char *s, size_t len)
+{
+       size_t h = 5381;
+       while (len--)
+               h = h * 33 + *s++;
+       return h & (HASH_SIZE - 1);
+}
 
 static struct buildhash hash_table[HASH_SIZE];
 
@@ -543,13 +553,13 @@
                SLIST_INIT(&hash_table[i]);
 
        for (i = 0; i < len_jobs; ++i) {
-               hash = HASH_ITEM(jobs[i].pkgname);
+               hash = hash_item(jobs[i].pkgname, jobs[i].pkgname_len);
                SLIST_INSERT_HEAD(&hash_table[hash], &jobs[i], hash_link);
        }
 }
 
 static struct buildhash *
-get_hash_chain(const char *pkgname)
+get_hash_chain(const char *pkgname, size_t len)
 {
-       return &hash_table[HASH_ITEM(pkgname)];
+       return &hash_table[hash_item(pkgname, len)];
 }
diff -r 1b36cf5eb0ac -r 622ba9223130 pkgtools/pbulk/files/pbulk/pbuild/pbuild.h
--- a/pkgtools/pbulk/files/pbulk/pbuild/pbuild.h        Sun Nov 27 19:50:23 2011 +0000
+++ b/pkgtools/pbulk/files/pbulk/pbuild/pbuild.h        Sun Nov 27 19:53:30 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: pbuild.h,v 1.5 2008/09/14 18:59:02 joerg Exp $ */
+/* $NetBSD: pbuild.h,v 1.6 2011/11/27 19:53:30 joerg Exp $ */
 
 /*-
  * Copyright (c) 2007 Joerg Sonnenberger <joerg%NetBSD.org@localhost>.
@@ -82,6 +82,7 @@
 struct build_job {
        /** The package name, including the version number. */
        char *pkgname;
+       size_t pkgname_len;
 
        /**
         * Pointers into the output from pbulk-resolve. The lines



Home | Main Index | Thread Index | Old Index