mirror of
https://github.com/moparisthebest/pacman
synced 2025-03-01 09:51:50 -05:00
Improved alpm_list_mmerge() performance (fixed coding style)
Improved alpm_list_mmerge() performance by removing an extra pass to obtain the tail node. This was actually suggested by a TODO comment. Signed-off-by: Diogo Sousa <diogogsousa@gmail.com> Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
parent
30d978a966
commit
268d0bbcbe
@ -206,12 +206,18 @@ alpm_list_t SYMEXPORT *alpm_list_join(alpm_list_t *first, alpm_list_t *second)
|
|||||||
*/
|
*/
|
||||||
alpm_list_t SYMEXPORT *alpm_list_mmerge(alpm_list_t *left, alpm_list_t *right, alpm_list_fn_cmp fn)
|
alpm_list_t SYMEXPORT *alpm_list_mmerge(alpm_list_t *left, alpm_list_t *right, alpm_list_fn_cmp fn)
|
||||||
{
|
{
|
||||||
alpm_list_t *newlist, *lp;
|
alpm_list_t *newlist, *lp, *tail_ptr, *left_tail_ptr, *right_tail_ptr;
|
||||||
|
|
||||||
if(left == NULL)
|
if(left == NULL) {
|
||||||
return right;
|
return right;
|
||||||
if(right == NULL)
|
}
|
||||||
|
if(right == NULL) {
|
||||||
return left;
|
return left;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Save tail node pointers for future use */
|
||||||
|
left_tail_ptr = left->prev;
|
||||||
|
right_tail_ptr = right->prev;
|
||||||
|
|
||||||
if(fn(left->data, right->data) <= 0) {
|
if(fn(left->data, right->data) <= 0) {
|
||||||
newlist = left;
|
newlist = left;
|
||||||
@ -242,19 +248,18 @@ alpm_list_t SYMEXPORT *alpm_list_mmerge(alpm_list_t *left, alpm_list_t *right, a
|
|||||||
if(left != NULL) {
|
if(left != NULL) {
|
||||||
lp->next = left;
|
lp->next = left;
|
||||||
left->prev = lp;
|
left->prev = lp;
|
||||||
|
tail_ptr = left_tail_ptr;
|
||||||
}
|
}
|
||||||
else if(right != NULL) {
|
else if(right != NULL) {
|
||||||
lp->next = right;
|
lp->next = right;
|
||||||
right->prev = lp;
|
right->prev = lp;
|
||||||
|
tail_ptr = right_tail_ptr;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
tail_ptr = lp;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Find our tail pointer
|
newlist->prev = tail_ptr;
|
||||||
* TODO maintain this in the algorithm itself */
|
|
||||||
lp = newlist;
|
|
||||||
while(lp && lp->next) {
|
|
||||||
lp = lp->next;
|
|
||||||
}
|
|
||||||
newlist->prev = lp;
|
|
||||||
|
|
||||||
return newlist;
|
return newlist;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user