From 0ca4751b774e65d1a22ad3fbebe2d325e6e63a9f Mon Sep 17 00:00:00 2001 From: Werner Almesberger Date: Fri, 19 Nov 2010 15:26:24 -0300 Subject: [PATCH] qpkg: some cleanup, prerequisite search speedup With the reduction of search depth, "prereq abiword" takes about 3 minutes on my PC. (Obviously, this can still be improved.) - gobble.c (gobble_buf): if pkg->id->value is NULL, just it as such - prereq.c (push): abort if trying to consider a package already considered or installed - prereq.c (conflicts): before being satisfied with using an installed package, make sure it really satisfies the requirement - prereq.c (conflicts): abort if an installed package conflicts - prereq.c (conflicts): added some debugging output (temporary) - prereq.c (conflicts): cut the search if we can't do better than a previous match --- qpkg/gobble.c | 2 +- qpkg/prereq.c | 20 ++++++++++++++++++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/qpkg/gobble.c b/qpkg/gobble.c index 7f75d88..76aeb28 100644 --- a/qpkg/gobble.c +++ b/qpkg/gobble.c @@ -241,7 +241,7 @@ package: WHITESPACE; pkg = alloc_type(struct pkg); pkg->id = ID(packages); - pkg->more = pkg->id->value ? pkg->id->value : NULL; + pkg->more = pkg->id->value; pkg->id->value = pkg; pkg->version = NULL; pkg->filename = NULL; diff --git a/qpkg/prereq.c b/qpkg/prereq.c index c503d9d..a6865b9 100644 --- a/qpkg/prereq.c +++ b/qpkg/prereq.c @@ -111,6 +111,7 @@ static void push(struct pkg *pkg) } stack[n_stack++] = pkg; + assert(!pkg->mark && !pkg->installed); pkg->mark = 1; } @@ -158,6 +159,7 @@ static int conflicts(const struct pkg *pkg, const struct list *conf) static void resolve(struct list *next_dep, const struct ref *dep, struct list *conf) { +static int level = 0; struct list more_deps; struct list more_conf = { .next = conf @@ -173,14 +175,27 @@ static void resolve(struct list *next_dep, const struct ref *dep, next_dep = next_dep->next; } for (pkg = dep->pkg->value; pkg; pkg = pkg->more) { + if (best && n_stack == n_best) + return; +#if 0 +fprintf(stderr, "%*s", level, ""); +fprintf(stderr, "%.*s %p", ID2S(pkg->id), pkg); +if (pkg->version) +fprintf(stderr, " %.*s", ID2S(pkg->version)); +if (pkg->mark) fprintf(stderr, " +"); +if (pkg->installed) fprintf(stderr, " ***"); +fprintf(stderr, "\n"); +#endif + if (!satisfies(pkg, dep)) + continue; if (pkg->installed || pkg->mark) { + assert(!conflicts(pkg, conf)); resolve(next_dep, dep->next, conf); continue; } - if (!satisfies(pkg, dep)) - continue; if (conflicts(pkg, conf)) continue; +level++; push(pkg); more_deps.refs = pkg->depends; more_deps.next = next_dep; @@ -189,6 +204,7 @@ static void resolve(struct list *next_dep, const struct ref *dep, resolve(&more_deps, dep->next, &more_conf); next_dep = more_deps.next; pop(); +level--; } }