summaryrefslogtreecommitdiffstats
path: root/lib/libalpm/remove.c
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2011-07-19 11:47:29 +0200
committerDan McGee <dan@archlinux.org>2011-07-21 22:04:30 +0200
commitbb3dada8711fbb822513cd556167867b537f8986 (patch)
tree1230de6f94675777e9cdd4150779f4756995efa1 /lib/libalpm/remove.c
parent058ee1737182c2d5e900e0feba57f0d6496e735e (diff)
downloadpacman-bb3dada8711fbb822513cd556167867b537f8986.tar.gz
pacman-bb3dada8711fbb822513cd556167867b537f8986.tar.xz
Convert package filelists to an array instead of linked list
This accomplishes quite a few things with one rather invasive change. 1. Iteration is much more performant, due to a reduction in pointer chasing and linear item access. 2. Data structures are smaller- we no longer have the overhead of the linked list as the file struts are now laid out consecutively in memory. 3. Memory allocation has been massively reworked. Before, we would allocate three different pieces of memory per file item- the list struct, the file struct, and the copied filename. What this resulted in was massive fragmentation of memory when loading filelists since the memory allocator had to leave holes all over the place. The new situation here now removes the need for any list item allocation; allocates the file structs in contiguous memory (and reallocs as necessary), leaving only the strings as individually allocated. Tests using valgrind (massif) show some pretty significant memory reductions on the worst case `pacman -Ql > /dev/null` (366387 files on my machine): Before: Peak heap: 54,416,024 B Useful heap: 36,840,692 B Extra heap: 17,575,332 B After: Peak heap: 38,004,352 B Useful heap: 28,101,347 B Extra heap: 9,903,005 B Several small helper methods have been introduced, including a list to array conversion helper as well as a filelist merge sort that works directly on arrays. Signed-off-by: Dan McGee <dan@archlinux.org>
Diffstat (limited to 'lib/libalpm/remove.c')
-rw-r--r--lib/libalpm/remove.c25
1 files changed, 15 insertions, 10 deletions
diff --git a/lib/libalpm/remove.c b/lib/libalpm/remove.c
index 2c5d98cb..83c437f3 100644
--- a/lib/libalpm/remove.c
+++ b/lib/libalpm/remove.c
@@ -262,15 +262,15 @@ static void unlink_file(alpm_handle_t *handle, alpm_pkg_t *info,
local_pkgs = _alpm_db_get_pkgcache(handle->db_local);
for(local = local_pkgs; local && !found; local = local->next) {
alpm_pkg_t *local_pkg = local->data;
- alpm_list_t *files;
+ alpm_filelist_t *filelist;
/* we duplicated the package when we put it in the removal list, so we
* so we can't use direct pointer comparison here. */
if(_alpm_pkg_cmp(info, local_pkg) == 0) {
continue;
}
- files = alpm_pkg_get_files(local_pkg);
- if(_alpm_filelist_contains(files, fileobj->name)) {
+ filelist = alpm_pkg_get_files(local_pkg);
+ if(_alpm_filelist_contains(filelist, fileobj->name)) {
_alpm_log(handle, ALPM_LOG_DEBUG,
"keeping directory %s (owned by %s)\n", file, local_pkg->name);
found = 1;
@@ -320,11 +320,13 @@ int _alpm_remove_single_package(alpm_handle_t *handle,
alpm_pkg_t *oldpkg, alpm_pkg_t *newpkg,
size_t targ_count, size_t pkg_count)
{
- alpm_list_t *files, *skip_remove, *lp;
+ alpm_list_t *skip_remove;
size_t filenum = 0, position = 0;
const char *pkgname = oldpkg->name;
const char *pkgver = oldpkg->version;
+ alpm_filelist_t *filelist;
char scriptlet[PATH_MAX];
+ size_t i;
if(newpkg) {
_alpm_log(handle, ALPM_LOG_DEBUG, "removing old package first (%s-%s)\n",
@@ -349,7 +351,8 @@ int _alpm_remove_single_package(alpm_handle_t *handle,
}
if(newpkg) {
- alpm_list_t *newfiles, *b;
+ alpm_filelist_t *newfiles;
+ alpm_list_t *b;
skip_remove = alpm_list_join(
alpm_list_strdup(handle->trans->skip_remove),
alpm_list_strdup(handle->noupgrade));
@@ -371,9 +374,10 @@ int _alpm_remove_single_package(alpm_handle_t *handle,
skip_remove = alpm_list_strdup(handle->trans->skip_remove);
}
- files = alpm_pkg_get_files(oldpkg);
- for(lp = files; lp; lp = lp->next) {
- if(!can_remove_file(handle, lp->data, skip_remove)) {
+ filelist = alpm_pkg_get_files(oldpkg);
+ for(i = 0; i < filelist->count; i++) {
+ alpm_file_t *file = filelist->files + i;
+ if(!can_remove_file(handle, file, skip_remove)) {
_alpm_log(handle, ALPM_LOG_DEBUG,
"not removing package '%s', can't remove all files\n", pkgname);
RET_ERR(handle, ALPM_ERR_PKG_CANT_REMOVE, -1);
@@ -390,9 +394,10 @@ int _alpm_remove_single_package(alpm_handle_t *handle,
}
/* iterate through the list backwards, unlinking files */
- for(lp = alpm_list_last(files); lp; lp = alpm_list_previous(lp)) {
+ for(i = filelist->count; i > 0; i--) {
+ alpm_file_t *file = filelist->files + i - 1;
int percent;
- unlink_file(handle, oldpkg, lp->data, skip_remove,
+ unlink_file(handle, oldpkg, file, skip_remove,
handle->trans->flags & ALPM_TRANS_FLAG_NOSAVE);
if(!newpkg) {