Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Convert the job list into a hash table while here replace pkg_jobs_is_empty by pkg_jobs_count
Baptiste Daroussin committed 13 years ago
commit a66d22aec3f41ff86c9d313ada69cb4545970a8d
parent 2c0fc75
9 files changed +19 -29
modified libpkg/pkg.h
@@ -855,9 +855,9 @@ void pkg_jobs_free(struct pkg_jobs *jobs);
int pkg_jobs_add(struct pkg_jobs *jobs, struct pkg *pkg);

/**
-
 * Returns true if there are no jobs.
+
 * Returns the number of elements in the job queue
 */
-
int pkg_jobs_is_empty(struct pkg_jobs *jobs);
+
int pkg_jobs_count(struct pkg_jobs *jobs);

/**
 * Iterates over the packages in the jobs queue.
modified libpkg/pkg_jobs.c
@@ -58,7 +58,6 @@ pkg_jobs_new(struct pkg_jobs **j, pkg_jobs_t t, struct pkgdb *db, bool force,
		return (EPKG_FATAL);
	}

-
	STAILQ_INIT(&(*j)->jobs);
	(*j)->db = db;
	(*j)->type = t;
	if (dry_run)
@@ -72,39 +71,37 @@ pkg_jobs_new(struct pkg_jobs **j, pkg_jobs_t t, struct pkgdb *db, bool force,
void
pkg_jobs_free(struct pkg_jobs *j)
{
-
	struct pkg *p;
-

	if (j == NULL)
		return;

	if ((j->flags & PKG_JOB_FLAGS_DRY_RUN) == 0)
		pkgdb_unlock(j->db);

-
	while (!STAILQ_EMPTY(&j->jobs)) {
-
		p = STAILQ_FIRST(&j->jobs);
-
		STAILQ_REMOVE_HEAD(&j->jobs, next);
-
		pkg_free(p);
-
	}
+
	HASH_FREE(j->jobs, pkg, pkg_free);
+

	free(j);
}

int
pkg_jobs_add(struct pkg_jobs *j, struct pkg *pkg)
{
+
	char *origin;
+

	assert(j != NULL);
	assert(pkg != NULL);

-
	STAILQ_INSERT_TAIL(&j->jobs, pkg, next);
+
	pkg_get(pkg, PKG_ORIGIN, &origin);
+
	HASH_ADD_KEYPTR(hh, j->jobs, origin, strlen(origin), pkg);

	return (EPKG_OK);
}

int
-
pkg_jobs_is_empty(struct pkg_jobs *j)
+
pkg_jobs_count(struct pkg_jobs *j)
{
	assert(j != NULL);

-
	return (STAILQ_EMPTY(&j->jobs));
+
	return (HASH_COUNT(j->jobs));
}

int
@@ -112,15 +109,7 @@ pkg_jobs(struct pkg_jobs *j, struct pkg **pkg)
{
	assert(j != NULL);

-
	if (*pkg == NULL)
-
		*pkg = STAILQ_FIRST(&j->jobs);
-
	else
-
		*pkg = STAILQ_NEXT(*pkg, next);
-

-
	if (*pkg == NULL)
-
		return (EPKG_END);
-
	else
-
		return (EPKG_OK);
+
	HASH_NEXT(j->jobs, (*pkg));
}

static int
modified libpkg/private/pkg.h
@@ -99,6 +99,7 @@ struct pkg {
	int64_t		 time;
	lic_t		 licenselogic;
	pkg_t		 type;
+
	UT_hash_handle	 hh;
	STAILQ_ENTRY(pkg) next;
};

@@ -147,7 +148,7 @@ struct pkg_option {
};

struct pkg_jobs {
-
	STAILQ_HEAD(jobs, pkg) jobs;
+
	struct pkg	*jobs;
	struct pkgdb	*db;
	pkg_jobs_t	 type;
	unsigned	 flags;
modified pkg/autoremove.c
@@ -113,7 +113,7 @@ exec_autoremove(int argc, char **argv)
		humanize_number(size, sizeof(size), newsize - oldsize, "B", HN_AUTOSCALE, 0);
	}

-
	if (pkg_jobs_is_empty(jobs)) {
+
	if (pkg_jobs_count(jobs) == 0) {
		printf("Nothing to do.\n");
		retcode = 0;
		goto cleanup;
modified pkg/check.c
@@ -159,7 +159,7 @@ fix_deps(struct pkgdb *db, struct deps_head *dh, int nbpkgs, bool yes)
		pkg = NULL;
	}

-
	if (pkg_jobs_is_empty(jobs)) {
+
	if (pkg_jobs_count(jobs) == 0) {
		printf("\n>>> Unable to find packages for installation.\n\n");
		pkg_jobs_free(jobs);
		pkgdb_it_free(it);
modified pkg/delete.c
@@ -140,7 +140,7 @@ exec_delete(int argc, char **argv)
	}

	/* check if we have something to deinstall */
-
	if (pkg_jobs_is_empty(jobs)) {
+
	if (pkg_jobs_count(jobs) == 0) {
		if (argc == 0) {
			if (!quiet)
				printf("Nothing to do.\n");
modified pkg/fetch.c
@@ -131,7 +131,7 @@ exec_fetch(int argc, char **argv)
	
	pkgdb_it_free(it);

-
	if (pkg_jobs_is_empty(jobs))
+
	if (pkg_jobs_count(jobs) == 0)
		goto cleanup;

	if (!quiet) {
modified pkg/install.c
@@ -147,7 +147,7 @@ exec_install(int argc, char **argv)
	}
	pkgdb_it_free(it);

-
	if (pkg_jobs_is_empty(jobs))
+
	if (pkg_jobs_count(jobs) == 0)
		goto cleanup;

	/* print a summary before applying the jobs */
modified pkg/upgrade.c
@@ -119,7 +119,7 @@ exec_upgrade(int argc, char **argv)
	}
	pkgdb_it_free(it);

-
	if (pkg_jobs_is_empty(jobs)) {
+
	if (pkg_jobs_count(jobs) == 0) {
		if (!quiet)
			printf("Nothing to do\n");
		retcode = EXIT_SUCCESS;