summaryrefslogtreecommitdiffstats
path: root/lib/libalpm/alpm_list.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libalpm/alpm_list.c')
-rw-r--r--lib/libalpm/alpm_list.c36
1 files changed, 15 insertions, 21 deletions
diff --git a/lib/libalpm/alpm_list.c b/lib/libalpm/alpm_list.c
index 3aa4f9bc..39eded13 100644
--- a/lib/libalpm/alpm_list.c
+++ b/lib/libalpm/alpm_list.c
@@ -1,7 +1,7 @@
/*
* alpm_list.c
*
- * Copyright (c) 2006-2011 Pacman Development Team <pacman-dev@archlinux.org>
+ * Copyright (c) 2006-2012 Pacman Development Team <pacman-dev@archlinux.org>
* Copyright (c) 2002-2006 by Judd Vinet <jvinet@zeroflux.org>
*
* This program is free software; you can redistribute it and/or modify
@@ -204,7 +204,8 @@ alpm_list_t SYMEXPORT *alpm_list_join(alpm_list_t *first, alpm_list_t *second)
*
* @return the resultant list
*/
-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, *tail_ptr, *left_tail_ptr, *right_tail_ptr;
@@ -273,20 +274,26 @@ alpm_list_t SYMEXPORT *alpm_list_mmerge(alpm_list_t *left, alpm_list_t *right, a
*
* @return the resultant list
*/
-alpm_list_t SYMEXPORT *alpm_list_msort(alpm_list_t *list, size_t n, alpm_list_fn_cmp fn)
+alpm_list_t SYMEXPORT *alpm_list_msort(alpm_list_t *list, size_t n,
+ alpm_list_fn_cmp fn)
{
if(n > 1) {
- alpm_list_t *left = list;
- alpm_list_t *lastleft = alpm_list_nth(list, n/2 - 1);
- alpm_list_t *right = lastleft->next;
+ size_t half = n / 2;
+ size_t i = half - 1;
+ alpm_list_t *left = list, *lastleft = list, *right;
+
+ while(i--) {
+ lastleft = lastleft->next;
+ }
+ right = lastleft->next;
/* tidy new lists */
lastleft->next = NULL;
right->prev = left->prev;
left->prev = lastleft;
- left = alpm_list_msort(left, n/2, fn);
- right = alpm_list_msort(right, n - (n/2), fn);
+ left = alpm_list_msort(left, half, fn);
+ right = alpm_list_msort(right, n - half, fn);
list = alpm_list_mmerge(left, right, fn);
}
return list;
@@ -579,19 +586,6 @@ alpm_list_t SYMEXPORT *alpm_list_last(const alpm_list_t *list)
}
}
-/**
- * @brief Get the data member of a list node.
- *
- * @param node the list node
- *
- * @return the contained data, or NULL if none
- */
-void SYMEXPORT *alpm_list_getdata(const alpm_list_t *node)
-{
- if(node == NULL) return NULL;
- return node->data;
-}
-
/* Misc */
/**