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>
This commit is contained in:
Dan McGee 2011-12-12 13:05:10 -06:00
parent 8c8f043717
commit 370c873be5

View file

@ -387,11 +387,14 @@ alpm_list_t *_alpm_db_find_fileconflicts(alpm_handle_t *handle,
alpm_list_t *i, *conflicts = NULL; alpm_list_t *i, *conflicts = NULL;
size_t numtargs = alpm_list_count(upgrade); size_t numtargs = alpm_list_count(upgrade);
size_t current; size_t current;
size_t rootlen;
if(!upgrade) { if(!upgrade) {
return NULL; return NULL;
} }
rootlen = strlen(handle->root);
/* TODO this whole function needs a huge change, which hopefully will /* TODO this whole function needs a huge change, which hopefully will
* be possible with real transactions. Right now we only do half as much * 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 * 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'; path[pathlen - 1] = '\0';
} }
relative_path = path + strlen(handle->root); relative_path = path + rootlen;
/* Check remove list (will we remove the conflicting local file?) */ /* Check remove list (will we remove the conflicting local file?) */
for(k = remove; k && !resolved_conflict; k = k->next) { 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". */ * components can be safely checked as all directories are "unowned". */
if(!resolved_conflict && dbpkg && !S_ISLNK(lsbuf.st_mode)) { if(!resolved_conflict && dbpkg && !S_ISLNK(lsbuf.st_mode)) {
char *rpath = calloc(PATH_MAX, sizeof(char)); char *rpath = calloc(PATH_MAX, sizeof(char));
const char *relative_rpath;
if(realpath(path, 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)) { if(_alpm_filelist_contains(alpm_pkg_get_files(dbpkg), relative_rpath)) {
_alpm_log(handle, ALPM_LOG_DEBUG, _alpm_log(handle, ALPM_LOG_DEBUG,
"package contained the resolved realpath\n"); "package contained the resolved realpath\n");