diff options
author | Dan McGee <dan@archlinux.org> | 2011-07-19 11:47:29 +0200 |
---|---|---|
committer | Dan McGee <dan@archlinux.org> | 2011-07-21 22:04:30 +0200 |
commit | bb3dada8711fbb822513cd556167867b537f8986 (patch) | |
tree | 1230de6f94675777e9cdd4150779f4756995efa1 /src | |
parent | 058ee1737182c2d5e900e0feba57f0d6496e735e (diff) | |
download | pacman-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 'src')
-rw-r--r-- | src/pacman/package.c | 9 | ||||
-rw-r--r-- | src/pacman/query.c | 19 |
2 files changed, 16 insertions, 12 deletions
diff --git a/src/pacman/package.c b/src/pacman/package.c index afbac6b7..45afded2 100644 --- a/src/pacman/package.c +++ b/src/pacman/package.c @@ -230,15 +230,16 @@ void dump_pkg_backups(alpm_pkg_t *pkg) void dump_pkg_files(alpm_pkg_t *pkg, int quiet) { const char *pkgname, *root; - alpm_list_t *i, *pkgfiles; + alpm_filelist_t *pkgfiles; + size_t i; pkgname = alpm_pkg_get_name(pkg); pkgfiles = alpm_pkg_get_files(pkg); root = alpm_option_get_root(config->handle); - for(i = pkgfiles; i; i = alpm_list_next(i)) { - const alpm_file_t *file = alpm_list_getdata(i); - if(!quiet){ + for(i = 0; i < pkgfiles->count; i++) { + const alpm_file_t *file = pkgfiles->files + i; + if(!quiet) { fprintf(stdout, "%s %s%s\n", pkgname, root, file->name); } else { fprintf(stdout, "%s%s\n", root, file->name); diff --git a/src/pacman/query.c b/src/pacman/query.c index 251c4dd6..163c3319 100644 --- a/src/pacman/query.c +++ b/src/pacman/query.c @@ -191,12 +191,13 @@ static int query_fileowner(alpm_list_t *targets) free(dname); for(i = alpm_db_get_pkgcache(db_local); i && !found; i = alpm_list_next(i)) { - alpm_list_t *j; alpm_pkg_t *info = alpm_list_getdata(i); + alpm_filelist_t *filelist = alpm_pkg_get_files(info); + size_t i; - for(j = alpm_pkg_get_files(info); j && !found; j = alpm_list_next(j)) { + for(i = 0; i < filelist->count; i++) { + const alpm_file_t *file = filelist->files + i; char *ppath, *pdname; - const alpm_file_t *file = alpm_list_getdata(j); const char *pkgfile = file->name; /* avoid the costly resolve_path usage if the basenames don't match */ @@ -402,11 +403,12 @@ static int filter(alpm_pkg_t *pkg) * loop through files to check if they exist. */ static int check(alpm_pkg_t *pkg) { - alpm_list_t *i; - const char *root; + const char *root, *pkgname; int allfiles = 0, errors = 0; size_t rootlen; char f[PATH_MAX]; + alpm_filelist_t *filelist; + size_t i; root = alpm_option_get_root(config->handle); rootlen = strlen(root); @@ -417,10 +419,11 @@ static int check(alpm_pkg_t *pkg) } strcpy(f, root); - const char *pkgname = alpm_pkg_get_name(pkg); - for(i = alpm_pkg_get_files(pkg); i; i = alpm_list_next(i)) { + pkgname = alpm_pkg_get_name(pkg); + filelist = alpm_pkg_get_files(pkg); + for(i = 0; i < filelist->count; i++) { + const alpm_file_t *file = filelist->files + i; struct stat st; - const alpm_file_t *file = alpm_list_getdata(i); const char *path = file->name; if(rootlen + 1 + strlen(path) > PATH_MAX) { |