summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2011-02-03 03:46:29 +0100
committerAllan McRae <allan@archlinux.org>2011-02-04 00:55:46 +0100
commit1f145bcd1a4fb22d4cb548a3be64898f60820695 (patch)
tree5e2e8e3647d2c8a3ec44c90fc907f535bc4bd6a4 /lib
parent14fd1e63a2ce420c555c6de34a815a8b62a9859b (diff)
downloadpacman-1f145bcd1a4fb22d4cb548a3be64898f60820695.tar.gz
pacman-1f145bcd1a4fb22d4cb548a3be64898f60820695.tar.xz
Use alpm_list_remove_item in pkghash_remove
Removes the code that was duplicated and has now been refactored into a separate method. Signed-off-by: Dan McGee <dan@archlinux.org>
Diffstat (limited to 'lib')
-rw-r--r--lib/libalpm/pkghash.c35
1 files changed, 4 insertions, 31 deletions
diff --git a/lib/libalpm/pkghash.c b/lib/libalpm/pkghash.c
index 14056e37..3d420e1f 100644
--- a/lib/libalpm/pkghash.c
+++ b/lib/libalpm/pkghash.c
@@ -219,7 +219,8 @@ pmpkghash_t *_alpm_pkghash_add_sorted(pmpkghash_t *hash, pmpkg_t *pkg)
*
* @return the resultant hash
*/
-pmpkghash_t *_alpm_pkghash_remove(pmpkghash_t *hash, pmpkg_t *pkg, pmpkg_t **data)
+pmpkghash_t *_alpm_pkghash_remove(pmpkghash_t *hash, pmpkg_t *pkg,
+ pmpkg_t **data)
{
alpm_list_t *i;
size_t position;
@@ -239,36 +240,8 @@ pmpkghash_t *_alpm_pkghash_remove(pmpkghash_t *hash, pmpkg_t *pkg, pmpkg_t **dat
if(info->name_hash == pkg->name_hash &&
strcmp(info->name, pkg->name) == 0) {
- /* remove from list */
- /* TODO - refactor with alpm_list_remove */
- if(i == hash->list) {
- /* Special case: removing the head node which has a back reference to
- * the tail node */
- hash->list = i->next;
- if(hash->list) {
- hash->list->prev = i->prev;
- }
- i->prev = NULL;
- } else if(i == hash->list->prev) {
- /* Special case: removing the tail node, so we need to fix the back
- * reference on the head node. We also know tail != head. */
- if(i->prev) {
- /* i->next should always be null */
- i->prev->next = i->next;
- hash->list->prev = i->prev;
- i->prev = NULL;
- }
- } else {
- /* Normal case, non-head and non-tail node */
- if(i->next) {
- i->next->prev = i->prev;
- }
- if(i->prev) {
- i->prev->next = i->next;
- }
- }
-
- /* remove from hash */
+ /* remove from list and hash */
+ hash->list = alpm_list_remove_item(hash->list, i);
if(data) {
*data = info;
}