summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2011-12-12 13:05:10 -0600
committerDan McGee <dan@archlinux.org>2011-12-12 13:05:10 -0600
commit370c873be54a6ef74f86b5e77ff722f766ebf707 (patch)
tree385b003d95e85dc4608ec5b638e79f158740e65e
parent8c8f04371745dad0bafcea14b38b4570e0b24a31 (diff)
downloadpacman-370c873be54a6ef74f86b5e77ff722f766ebf707.tar.xz
Calculate root length only once when checking for file conflicts
It is quite easy to hoist this potentially repeated computation out of the loop; even if we don't end up using it, it is super cheap to do it only once. Signed-off-by: Dan McGee <dan@archlinux.org>
-rw-r--r--lib/libalpm/conflict.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/lib/libalpm/conflict.c b/lib/libalpm/conflict.c
index d89fc532..5703aba8 100644
--- a/lib/libalpm/conflict.c
+++ b/lib/libalpm/conflict.c
@@ -387,11 +387,14 @@ alpm_list_t *_alpm_db_find_fileconflicts(alpm_handle_t *handle,
alpm_list_t *i, *conflicts = NULL;
size_t numtargs = alpm_list_count(upgrade);
size_t current;
+ size_t rootlen;
if(!upgrade) {
return NULL;
}
+ rootlen = strlen(handle->root);
+
/* TODO this whole function needs a huge change, which hopefully will
* be possible with real transactions. Right now we only do half as much
* here as we do when we actually extract files in add.c with our 12
@@ -494,7 +497,7 @@ alpm_list_t *_alpm_db_find_fileconflicts(alpm_handle_t *handle,
path[pathlen - 1] = '\0';
}
- relative_path = path + strlen(handle->root);
+ relative_path = path + rootlen;
/* Check remove list (will we remove the conflicting local file?) */
for(k = remove; k && !resolved_conflict; k = k->next) {
@@ -547,9 +550,8 @@ alpm_list_t *_alpm_db_find_fileconflicts(alpm_handle_t *handle,
* components can be safely checked as all directories are "unowned". */
if(!resolved_conflict && dbpkg && !S_ISLNK(lsbuf.st_mode)) {
char *rpath = calloc(PATH_MAX, sizeof(char));
- const char *relative_rpath;
if(realpath(path, rpath)) {
- relative_rpath = rpath + strlen(handle->root);
+ const char *relative_rpath = rpath + rootlen;
if(_alpm_filelist_contains(alpm_pkg_get_files(dbpkg), relative_rpath)) {
_alpm_log(handle, ALPM_LOG_DEBUG,
"package contained the resolved realpath\n");