summaryrefslogtreecommitdiffstats
path: root/lib/libalpm/be_sync.c
diff options
context:
space:
mode:
authorAllan McRae <allan@archlinux.org>2011-01-25 02:49:34 +0100
committerAllan McRae <allan@archlinux.org>2011-02-04 00:55:45 +0100
commitf8fdce6cb0da4d832ffa730e0dacb5544c1f8154 (patch)
treeeeba547be38459b041b9fa8089f8171ba006ee19 /lib/libalpm/be_sync.c
parent5dae577a87795e7666f05613cf9aa7207fd17346 (diff)
downloadpacman-f8fdce6cb0da4d832ffa730e0dacb5544c1f8154.tar.gz
pacman-f8fdce6cb0da4d832ffa730e0dacb5544c1f8154.tar.xz
Read pkgcache into hash
Read the package information for sync/local databases into a pmpkghash_t structure. Provide a alpm_db_get_pkgcache_list() method that returns the list from the hash object. Most usages of alpm_db_get_pkgcache are converted to this at this stage for ease of implementation. Review whether these are better accessing the hash table directly at a later stage. Signed-off-by: Allan McRae <allan@archlinux.org>
Diffstat (limited to 'lib/libalpm/be_sync.c')
-rw-r--r--lib/libalpm/be_sync.c13
1 files changed, 9 insertions, 4 deletions
diff --git a/lib/libalpm/be_sync.c b/lib/libalpm/be_sync.c
index 0c968b45..2c70e2c5 100644
--- a/lib/libalpm/be_sync.c
+++ b/lib/libalpm/be_sync.c
@@ -232,6 +232,9 @@ static int sync_db_populate(pmdb_t *db)
}
est_count = estimate_package_count(&buf, archive);
+ /* initialize hash at 50% full */
+ db->pkgcache = _alpm_pkghash_create(est_count * 2);
+
while(archive_read_next_header(archive, &entry) == ARCHIVE_OK) {
const struct stat *st;
@@ -256,7 +259,7 @@ static int sync_db_populate(pmdb_t *db)
}
/* duplicated database entries are not allowed */
- if(_alpm_pkg_find(db->pkgcache, pkg->name)) {
+ if(_alpm_pkghash_find(db->pkgcache, pkg->name)) {
_alpm_log(PM_LOG_ERROR, _("duplicated database entry '%s'\n"), pkg->name);
_alpm_pkg_free(pkg);
continue;
@@ -269,7 +272,7 @@ static int sync_db_populate(pmdb_t *db)
/* add to the collection */
_alpm_log(PM_LOG_FUNCTION, "adding '%s' to package cache for db '%s'\n",
pkg->name, db->treename);
- db->pkgcache = alpm_list_add(db->pkgcache, pkg);
+ db->pkgcache = _alpm_pkghash_add(db->pkgcache, pkg);
count++;
} else {
/* we have desc, depends or deltas - parse it */
@@ -277,7 +280,9 @@ static int sync_db_populate(pmdb_t *db)
}
}
- db->pkgcache = alpm_list_msort(db->pkgcache, (size_t)count, _alpm_pkg_cmp);
+ if(count > 0) {
+ db->pkgcache->list = alpm_list_msort(db->pkgcache->list, (size_t)count, _alpm_pkg_cmp);
+ }
archive_read_finish(archive);
return(count);
@@ -343,7 +348,7 @@ static int sync_db_read(pmdb_t *db, struct archive *archive,
if(likely_pkg && strcmp(likely_pkg->name, pkgname) == 0) {
pkg = likely_pkg;
} else {
- pkg = _alpm_pkg_find(db->pkgcache, pkgname);
+ pkg = _alpm_pkghash_find(db->pkgcache, pkgname);
}
if(pkg == NULL) {
_alpm_log(PM_LOG_DEBUG, "package %s not found in %s sync database",