From 1f145bcd1a4fb22d4cb548a3be64898f60820695 Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Wed, 2 Feb 2011 20:46:29 -0600 Subject: 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 --- lib/libalpm/pkghash.c | 35 ++++------------------------------- 1 file 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; } -- cgit v1.2.3-70-g09d2