[pacman-dev] [PATCH] Remove alpm_list_first
The only thing this accessor did was remove the const qualifier given our entire list implementation requires passing around the head anyway. Signed-off-by: Allan McRae <allan@archlinux.org> --- lib/libalpm/alpm_list.c | 16 ---------------- lib/libalpm/alpm_list.h | 1 - src/pacman/util.c | 2 +- 3 files changed, 1 insertions(+), 18 deletions(-) diff --git a/lib/libalpm/alpm_list.c b/lib/libalpm/alpm_list.c index 1976e13..38cefa6 100644 --- a/lib/libalpm/alpm_list.c +++ b/lib/libalpm/alpm_list.c @@ -507,22 +507,6 @@ alpm_list_t SYMEXPORT *alpm_list_reverse(alpm_list_t *list) /* Accessors */ /** - * @brief Get the first element of a list. - * - * @param list the list - * - * @return the first element in the list - */ -inline alpm_list_t SYMEXPORT *alpm_list_first(const alpm_list_t *list) -{ - if(list) { - return (alpm_list_t *)list; - } else { - return NULL; - } -} - -/** * @brief Return nth element from list (starting from 0). * * @param list the list diff --git a/lib/libalpm/alpm_list.h b/lib/libalpm/alpm_list.h index 27a76d1..824e866 100644 --- a/lib/libalpm/alpm_list.h +++ b/lib/libalpm/alpm_list.h @@ -67,7 +67,6 @@ alpm_list_t *alpm_list_copy_data(const alpm_list_t *list, size_t size); alpm_list_t *alpm_list_reverse(alpm_list_t *list); /* item accessors */ -alpm_list_t *alpm_list_first(const alpm_list_t *list); 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); diff --git a/src/pacman/util.c b/src/pacman/util.c index 9ced7aa..a24c4ea 100644 --- a/src/pacman/util.c +++ b/src/pacman/util.c @@ -767,7 +767,7 @@ out: /* cleanup */ if(config->verbosepkglists) { /* targets is a list of lists of strings, free inner lists here */ - for(j = alpm_list_first(targets); j; j = alpm_list_next(j)) { + for(j = targets; j; j = alpm_list_next(j)) { lp = alpm_list_getdata(j); FREELIST(lp); } -- 1.7.6
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> --- lib/libalpm/alpm_list.c | 7 +++---- lib/libalpm/alpm_list.h | 2 +- lib/libalpm/remove.c | 4 ++-- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/lib/libalpm/alpm_list.c b/lib/libalpm/alpm_list.c index 38cefa6..071cd99 100644 --- a/lib/libalpm/alpm_list.c +++ b/lib/libalpm/alpm_list.c @@ -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; } diff --git a/lib/libalpm/alpm_list.h b/lib/libalpm/alpm_list.h index 824e866..5e8ca46 100644 --- a/lib/libalpm/alpm_list.h +++ b/lib/libalpm/alpm_list.h @@ -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); diff --git a/lib/libalpm/remove.c b/lib/libalpm/remove.c index 59374dc..9b8517c 100644 --- a/lib/libalpm/remove.c +++ b/lib/libalpm/remove.c @@ -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); -- 1.7.6
On Mon, Jul 4, 2011 at 4:16 AM, Allan McRae <allan@archlinux.org> wrote:
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.
This works even for single item list where the first item is the last, so node->prev == node. ACK
participants (2)
-
Allan McRae
-
Xavier Chantry