Simplify alpm_list_previous

We can readily detect the first node in a list by checking if
node->prev->next is NULL. So there is no need to pass the head
of the list to this function and its prototype now looks like
all the other item accessors.

Signed-off-by: Allan McRae <allan@archlinux.org>
Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
Allan McRae 2011-07-04 11:17:12 +10:00 committed by Dan McGee
parent 97103f860d
commit 24324ff0e1
3 changed files with 6 additions and 7 deletions

View File

@ -547,11 +547,10 @@ inline alpm_list_t SYMEXPORT *alpm_list_next(const alpm_list_t *node)
*
* @return the previous element, or NULL when no previous element exist
*/
inline alpm_list_t SYMEXPORT *alpm_list_previous(const alpm_list_t *list,
const alpm_list_t *node)
inline alpm_list_t SYMEXPORT *alpm_list_previous(const alpm_list_t *list)
{
if(node && node != list) {
return node->prev;
if(list && list->prev->next) {
return list->prev;
} else {
return NULL;
}

View File

@ -69,7 +69,7 @@ alpm_list_t *alpm_list_reverse(alpm_list_t *list);
/* item accessors */
alpm_list_t *alpm_list_nth(const alpm_list_t *list, size_t n);
alpm_list_t *alpm_list_next(const alpm_list_t *list);
alpm_list_t *alpm_list_previous(const alpm_list_t *list, const alpm_list_t *node);
alpm_list_t *alpm_list_previous(const alpm_list_t *list);
alpm_list_t *alpm_list_last(const alpm_list_t *list);
void *alpm_list_getdata(const alpm_list_t *entry);

View File

@ -329,7 +329,7 @@ int _alpm_upgraderemove_package(alpm_handle_t *handle,
_alpm_log(handle, ALPM_LOG_DEBUG, "removing %ld files\n", (unsigned long)filenum);
/* iterate through the list backwards, unlinking files */
for(lp = alpm_list_last(files); lp; lp = alpm_list_previous(files, lp)) {
for(lp = alpm_list_last(files); lp; lp = alpm_list_previous(lp)) {
unlink_file(handle, oldpkg, lp->data, skip_remove, 0);
}
FREELIST(skip_remove);
@ -406,7 +406,7 @@ int _alpm_remove_packages(alpm_handle_t *handle)
pkg_count, (pkg_count - targcount + 1));
/* iterate through the list backwards, unlinking files */
for(lp = alpm_list_last(files); lp; lp = alpm_list_previous(files, lp)) {
for(lp = alpm_list_last(files); lp; lp = alpm_list_previous(lp)) {
int percent;
unlink_file(handle, info, lp->data, NULL, trans->flags & ALPM_TRANS_FLAG_NOSAVE);