From 370c873be54a6ef74f86b5e77ff722f766ebf707 Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Mon, 12 Dec 2011 13:05:10 -0600 Subject: 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 --- lib/libalpm/conflict.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'lib') 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"); -- cgit v1.2.3-70-g09d2