mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-12-26 15:36:14 +01:00
Remove redundant header inclusions
This commit is contained in:
parent
d95c6b8834
commit
8f81ee86ee
339
glib/gslist.c
339
glib/gslist.c
@ -21,16 +21,17 @@
|
||||
* Modified by the GLib Team and others 1997-2000. See the AUTHORS
|
||||
* file for a list of people on the GLib Team. See the ChangeLog
|
||||
* files for a list of changes. These files are distributed with
|
||||
* GLib at ftp://ftp.gtk.org/pub/gtk/.
|
||||
* GLib at ftp://ftp.gtk.org/pub/gtk/.
|
||||
*/
|
||||
|
||||
/*
|
||||
/*
|
||||
* MT safe
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "glib.h"
|
||||
#include "gslist.h"
|
||||
#include "gtestutils.h"
|
||||
|
||||
/**
|
||||
* SECTION: linked_lists_single
|
||||
@ -168,7 +169,7 @@ g_slist_free (GSList *list)
|
||||
/**
|
||||
* g_slist_free_1:
|
||||
* @list: a #GSList element
|
||||
*
|
||||
*
|
||||
* Frees one #GSList element.
|
||||
* It is usually used after g_slist_remove_link().
|
||||
*/
|
||||
@ -193,14 +194,14 @@ g_slist_free_1 (GSList *list)
|
||||
* Adds a new element on to the end of the list.
|
||||
*
|
||||
* <note><para>
|
||||
* The return value is the new start of the list, which may
|
||||
* The return value is the new start of the list, which may
|
||||
* have changed, so make sure you store the new value.
|
||||
* </para></note>
|
||||
*
|
||||
* <note><para>
|
||||
* Note that g_slist_append() has to traverse the entire list
|
||||
* to find the end, which is inefficient when adding multiple
|
||||
* elements. A common idiom to avoid the inefficiency is to prepend
|
||||
* Note that g_slist_append() has to traverse the entire list
|
||||
* to find the end, which is inefficient when adding multiple
|
||||
* elements. A common idiom to avoid the inefficiency is to prepend
|
||||
* the elements and reverse the list when all elements have been added.
|
||||
* </para></note>
|
||||
*
|
||||
@ -221,7 +222,7 @@ g_slist_free_1 (GSList *list)
|
||||
*/
|
||||
GSList*
|
||||
g_slist_append (GSList *list,
|
||||
gpointer data)
|
||||
gpointer data)
|
||||
{
|
||||
GSList *new_list;
|
||||
GSList *last;
|
||||
@ -250,7 +251,7 @@ g_slist_append (GSList *list,
|
||||
* Adds a new element on to the start of the list.
|
||||
*
|
||||
* <note><para>
|
||||
* The return value is the new start of the list, which
|
||||
* The return value is the new start of the list, which
|
||||
* may have changed, so make sure you store the new value.
|
||||
* </para></note>
|
||||
*
|
||||
@ -265,7 +266,7 @@ g_slist_append (GSList *list,
|
||||
*/
|
||||
GSList*
|
||||
g_slist_prepend (GSList *list,
|
||||
gpointer data)
|
||||
gpointer data)
|
||||
{
|
||||
GSList *new_list;
|
||||
|
||||
@ -280,8 +281,8 @@ g_slist_prepend (GSList *list,
|
||||
* g_slist_insert:
|
||||
* @list: a #GSList
|
||||
* @data: the data for the new element
|
||||
* @position: the position to insert the element.
|
||||
* If this is negative, or is larger than the number
|
||||
* @position: the position to insert the element.
|
||||
* If this is negative, or is larger than the number
|
||||
* of elements in the list, the new element is added on
|
||||
* to the end of the list.
|
||||
*
|
||||
@ -291,8 +292,8 @@ g_slist_prepend (GSList *list,
|
||||
*/
|
||||
GSList*
|
||||
g_slist_insert (GSList *list,
|
||||
gpointer data,
|
||||
gint position)
|
||||
gpointer data,
|
||||
gint position)
|
||||
{
|
||||
GSList *prev_list;
|
||||
GSList *tmp_list;
|
||||
@ -341,14 +342,14 @@ g_slist_insert (GSList *list,
|
||||
* @sibling: node to insert @data before
|
||||
* @data: data to put in the newly-inserted node
|
||||
*
|
||||
* Inserts a node before @sibling containing @data.
|
||||
*
|
||||
* Inserts a node before @sibling containing @data.
|
||||
*
|
||||
* Returns: the new head of the list.
|
||||
*/
|
||||
GSList*
|
||||
g_slist_insert_before (GSList *slist,
|
||||
GSList *sibling,
|
||||
gpointer data)
|
||||
GSList *sibling,
|
||||
gpointer data)
|
||||
{
|
||||
if (!slist)
|
||||
{
|
||||
@ -363,25 +364,25 @@ g_slist_insert_before (GSList *slist,
|
||||
GSList *node, *last = NULL;
|
||||
|
||||
for (node = slist; node; last = node, node = last->next)
|
||||
if (node == sibling)
|
||||
break;
|
||||
if (node == sibling)
|
||||
break;
|
||||
if (!last)
|
||||
{
|
||||
node = _g_slist_alloc ();
|
||||
node->data = data;
|
||||
node->next = slist;
|
||||
{
|
||||
node = _g_slist_alloc ();
|
||||
node->data = data;
|
||||
node->next = slist;
|
||||
|
||||
return node;
|
||||
}
|
||||
return node;
|
||||
}
|
||||
else
|
||||
{
|
||||
node = _g_slist_alloc ();
|
||||
node->data = data;
|
||||
node->next = last->next;
|
||||
last->next = node;
|
||||
{
|
||||
node = _g_slist_alloc ();
|
||||
node->data = data;
|
||||
node->next = last->next;
|
||||
last->next = node;
|
||||
|
||||
return slist;
|
||||
}
|
||||
return slist;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -402,9 +403,9 @@ g_slist_concat (GSList *list1, GSList *list2)
|
||||
if (list2)
|
||||
{
|
||||
if (list1)
|
||||
g_slist_last (list1)->next = list2;
|
||||
g_slist_last (list1)->next = list2;
|
||||
else
|
||||
list1 = list2;
|
||||
list1 = list2;
|
||||
}
|
||||
|
||||
return list1;
|
||||
@ -423,7 +424,7 @@ g_slist_concat (GSList *list1, GSList *list2)
|
||||
*/
|
||||
GSList*
|
||||
g_slist_remove (GSList *list,
|
||||
gconstpointer data)
|
||||
gconstpointer data)
|
||||
{
|
||||
GSList *tmp, *prev = NULL;
|
||||
|
||||
@ -431,15 +432,15 @@ g_slist_remove (GSList *list,
|
||||
while (tmp)
|
||||
{
|
||||
if (tmp->data == data)
|
||||
{
|
||||
if (prev)
|
||||
prev->next = tmp->next;
|
||||
else
|
||||
list = tmp->next;
|
||||
{
|
||||
if (prev)
|
||||
prev->next = tmp->next;
|
||||
else
|
||||
list = tmp->next;
|
||||
|
||||
g_slist_free_1 (tmp);
|
||||
break;
|
||||
}
|
||||
g_slist_free_1 (tmp);
|
||||
break;
|
||||
}
|
||||
prev = tmp;
|
||||
tmp = prev->next;
|
||||
}
|
||||
@ -452,16 +453,16 @@ g_slist_remove (GSList *list,
|
||||
* @list: a #GSList
|
||||
* @data: data to remove
|
||||
*
|
||||
* Removes all list nodes with data equal to @data.
|
||||
* Returns the new head of the list. Contrast with
|
||||
* g_slist_remove() which removes only the first node
|
||||
* Removes all list nodes with data equal to @data.
|
||||
* Returns the new head of the list. Contrast with
|
||||
* g_slist_remove() which removes only the first node
|
||||
* matching the given data.
|
||||
*
|
||||
* Returns: new head of @list
|
||||
*/
|
||||
GSList*
|
||||
g_slist_remove_all (GSList *list,
|
||||
gconstpointer data)
|
||||
gconstpointer data)
|
||||
{
|
||||
GSList *tmp, *prev = NULL;
|
||||
|
||||
@ -469,22 +470,22 @@ g_slist_remove_all (GSList *list,
|
||||
while (tmp)
|
||||
{
|
||||
if (tmp->data == data)
|
||||
{
|
||||
GSList *next = tmp->next;
|
||||
{
|
||||
GSList *next = tmp->next;
|
||||
|
||||
if (prev)
|
||||
prev->next = next;
|
||||
else
|
||||
list = next;
|
||||
|
||||
g_slist_free_1 (tmp);
|
||||
tmp = next;
|
||||
}
|
||||
if (prev)
|
||||
prev->next = next;
|
||||
else
|
||||
list = next;
|
||||
|
||||
g_slist_free_1 (tmp);
|
||||
tmp = next;
|
||||
}
|
||||
else
|
||||
{
|
||||
prev = tmp;
|
||||
tmp = prev->next;
|
||||
}
|
||||
{
|
||||
prev = tmp;
|
||||
tmp = prev->next;
|
||||
}
|
||||
}
|
||||
|
||||
return list;
|
||||
@ -492,7 +493,7 @@ g_slist_remove_all (GSList *list,
|
||||
|
||||
static inline GSList*
|
||||
_g_slist_remove_link (GSList *list,
|
||||
GSList *link)
|
||||
GSList *link)
|
||||
{
|
||||
GSList *tmp;
|
||||
GSList *prev;
|
||||
@ -503,15 +504,15 @@ _g_slist_remove_link (GSList *list,
|
||||
while (tmp)
|
||||
{
|
||||
if (tmp == link)
|
||||
{
|
||||
if (prev)
|
||||
prev->next = tmp->next;
|
||||
if (list == tmp)
|
||||
list = list->next;
|
||||
{
|
||||
if (prev)
|
||||
prev->next = tmp->next;
|
||||
if (list == tmp)
|
||||
list = list->next;
|
||||
|
||||
tmp->next = NULL;
|
||||
break;
|
||||
}
|
||||
tmp->next = NULL;
|
||||
break;
|
||||
}
|
||||
|
||||
prev = tmp;
|
||||
tmp = tmp->next;
|
||||
@ -525,16 +526,16 @@ _g_slist_remove_link (GSList *list,
|
||||
* @list: a #GSList
|
||||
* @link_: an element in the #GSList
|
||||
*
|
||||
* Removes an element from a #GSList, without
|
||||
* freeing the element. The removed element's next
|
||||
* Removes an element from a #GSList, without
|
||||
* freeing the element. The removed element's next
|
||||
* link is set to %NULL, so that it becomes a
|
||||
* self-contained list with one element.
|
||||
*
|
||||
* Returns: the new start of the #GSList, without the element
|
||||
*/
|
||||
GSList*
|
||||
GSList*
|
||||
g_slist_remove_link (GSList *list,
|
||||
GSList *link_)
|
||||
GSList *link_)
|
||||
{
|
||||
return _g_slist_remove_link (list, link_);
|
||||
}
|
||||
@ -544,15 +545,15 @@ g_slist_remove_link (GSList *list,
|
||||
* @list: a #GSList
|
||||
* @link_: node to delete
|
||||
*
|
||||
* Removes the node link_ from the list and frees it.
|
||||
* Compare this to g_slist_remove_link() which removes the node
|
||||
* Removes the node link_ from the list and frees it.
|
||||
* Compare this to g_slist_remove_link() which removes the node
|
||||
* without freeing it.
|
||||
*
|
||||
* Returns: the new head of @list
|
||||
*/
|
||||
GSList*
|
||||
g_slist_delete_link (GSList *list,
|
||||
GSList *link_)
|
||||
GSList *link_)
|
||||
{
|
||||
list = _g_slist_remove_link (list, link_);
|
||||
_g_slist_free1 (link_);
|
||||
@ -563,12 +564,12 @@ g_slist_delete_link (GSList *list,
|
||||
/**
|
||||
* g_slist_copy:
|
||||
* @list: a #GSList
|
||||
*
|
||||
*
|
||||
* Copies a #GSList.
|
||||
*
|
||||
*
|
||||
* <note><para>
|
||||
* Note that this is a "shallow" copy. If the list elements
|
||||
* consist of pointers to data, the pointers are copied but
|
||||
* Note that this is a "shallow" copy. If the list elements
|
||||
* consist of pointers to data, the pointers are copied but
|
||||
* the actual data isn't.
|
||||
* </para></note>
|
||||
*
|
||||
@ -588,12 +589,12 @@ g_slist_copy (GSList *list)
|
||||
last = new_list;
|
||||
list = list->next;
|
||||
while (list)
|
||||
{
|
||||
last->next = _g_slist_alloc ();
|
||||
last = last->next;
|
||||
last->data = list->data;
|
||||
list = list->next;
|
||||
}
|
||||
{
|
||||
last->next = _g_slist_alloc ();
|
||||
last = last->next;
|
||||
last->data = list->data;
|
||||
list = list->next;
|
||||
}
|
||||
last->next = NULL;
|
||||
}
|
||||
|
||||
@ -612,17 +613,17 @@ GSList*
|
||||
g_slist_reverse (GSList *list)
|
||||
{
|
||||
GSList *prev = NULL;
|
||||
|
||||
|
||||
while (list)
|
||||
{
|
||||
GSList *next = list->next;
|
||||
|
||||
list->next = prev;
|
||||
|
||||
|
||||
prev = list;
|
||||
list = next;
|
||||
}
|
||||
|
||||
|
||||
return prev;
|
||||
}
|
||||
|
||||
@ -633,12 +634,12 @@ g_slist_reverse (GSList *list)
|
||||
*
|
||||
* Gets the element at the given position in a #GSList.
|
||||
*
|
||||
* Returns: the element, or %NULL if the position is off
|
||||
* Returns: the element, or %NULL if the position is off
|
||||
* the end of the #GSList
|
||||
*/
|
||||
GSList*
|
||||
g_slist_nth (GSList *list,
|
||||
guint n)
|
||||
guint n)
|
||||
{
|
||||
while (n-- > 0 && list)
|
||||
list = list->next;
|
||||
@ -653,12 +654,12 @@ g_slist_nth (GSList *list,
|
||||
*
|
||||
* Gets the data of the element at the given position.
|
||||
*
|
||||
* Returns: the element's data, or %NULL if the position
|
||||
* Returns: the element's data, or %NULL if the position
|
||||
* is off the end of the #GSList
|
||||
*/
|
||||
gpointer
|
||||
g_slist_nth_data (GSList *list,
|
||||
guint n)
|
||||
guint n)
|
||||
{
|
||||
while (n-- > 0 && list)
|
||||
list = list->next;
|
||||
@ -671,20 +672,20 @@ g_slist_nth_data (GSList *list,
|
||||
* @list: a #GSList
|
||||
* @data: the element data to find
|
||||
*
|
||||
* Finds the element in a #GSList which
|
||||
* Finds the element in a #GSList which
|
||||
* contains the given data.
|
||||
*
|
||||
* Returns: the found #GSList element,
|
||||
* Returns: the found #GSList element,
|
||||
* or %NULL if it is not found
|
||||
*/
|
||||
GSList*
|
||||
g_slist_find (GSList *list,
|
||||
gconstpointer data)
|
||||
gconstpointer data)
|
||||
{
|
||||
while (list)
|
||||
{
|
||||
if (list->data == data)
|
||||
break;
|
||||
break;
|
||||
list = list->next;
|
||||
}
|
||||
|
||||
@ -696,29 +697,29 @@ g_slist_find (GSList *list,
|
||||
* g_slist_find_custom:
|
||||
* @list: a #GSList
|
||||
* @data: user data passed to the function
|
||||
* @func: the function to call for each element.
|
||||
* @func: the function to call for each element.
|
||||
* It should return 0 when the desired element is found
|
||||
*
|
||||
* Finds an element in a #GSList, using a supplied function to
|
||||
* find the desired element. It iterates over the list, calling
|
||||
* the given function which should return 0 when the desired
|
||||
* element is found. The function takes two #gconstpointer arguments,
|
||||
* the #GSList element's data as the first argument and the
|
||||
* Finds an element in a #GSList, using a supplied function to
|
||||
* find the desired element. It iterates over the list, calling
|
||||
* the given function which should return 0 when the desired
|
||||
* element is found. The function takes two #gconstpointer arguments,
|
||||
* the #GSList element's data as the first argument and the
|
||||
* given user data.
|
||||
*
|
||||
* Returns: the found #GSList element, or %NULL if it is not found
|
||||
*/
|
||||
GSList*
|
||||
g_slist_find_custom (GSList *list,
|
||||
gconstpointer data,
|
||||
GCompareFunc func)
|
||||
gconstpointer data,
|
||||
GCompareFunc func)
|
||||
{
|
||||
g_return_val_if_fail (func != NULL, list);
|
||||
|
||||
while (list)
|
||||
{
|
||||
if (! func (list->data, data))
|
||||
return list;
|
||||
return list;
|
||||
list = list->next;
|
||||
}
|
||||
|
||||
@ -730,15 +731,15 @@ g_slist_find_custom (GSList *list,
|
||||
* @list: a #GSList
|
||||
* @llink: an element in the #GSList
|
||||
*
|
||||
* Gets the position of the given element
|
||||
* Gets the position of the given element
|
||||
* in the #GSList (starting from 0).
|
||||
*
|
||||
* Returns: the position of the element in the #GSList,
|
||||
* Returns: the position of the element in the #GSList,
|
||||
* or -1 if the element is not found
|
||||
*/
|
||||
gint
|
||||
g_slist_position (GSList *list,
|
||||
GSList *llink)
|
||||
GSList *llink)
|
||||
{
|
||||
gint i;
|
||||
|
||||
@ -746,7 +747,7 @@ g_slist_position (GSList *list,
|
||||
while (list)
|
||||
{
|
||||
if (list == llink)
|
||||
return i;
|
||||
return i;
|
||||
i++;
|
||||
list = list->next;
|
||||
}
|
||||
@ -759,15 +760,15 @@ g_slist_position (GSList *list,
|
||||
* @list: a #GSList
|
||||
* @data: the data to find
|
||||
*
|
||||
* Gets the position of the element containing
|
||||
* Gets the position of the element containing
|
||||
* the given data (starting from 0).
|
||||
*
|
||||
* Returns: the index of the element containing the data,
|
||||
* Returns: the index of the element containing the data,
|
||||
* or -1 if the data is not found
|
||||
*/
|
||||
gint
|
||||
g_slist_index (GSList *list,
|
||||
gconstpointer data)
|
||||
gconstpointer data)
|
||||
{
|
||||
gint i;
|
||||
|
||||
@ -775,7 +776,7 @@ g_slist_index (GSList *list,
|
||||
while (list)
|
||||
{
|
||||
if (list->data == data)
|
||||
return i;
|
||||
return i;
|
||||
i++;
|
||||
list = list->next;
|
||||
}
|
||||
@ -785,15 +786,15 @@ g_slist_index (GSList *list,
|
||||
|
||||
/**
|
||||
* g_slist_last:
|
||||
* @list: a #GSList
|
||||
* @list: a #GSList
|
||||
*
|
||||
* Gets the last element in a #GSList.
|
||||
*
|
||||
*
|
||||
* <note><para>
|
||||
* This function iterates over the whole list.
|
||||
* </para></note>
|
||||
*
|
||||
* Returns: the last element in the #GSList,
|
||||
* Returns: the last element in the #GSList,
|
||||
* or %NULL if the #GSList has no elements
|
||||
*/
|
||||
GSList*
|
||||
@ -802,7 +803,7 @@ g_slist_last (GSList *list)
|
||||
if (list)
|
||||
{
|
||||
while (list->next)
|
||||
list = list->next;
|
||||
list = list->next;
|
||||
}
|
||||
|
||||
return list;
|
||||
@ -815,7 +816,7 @@ g_slist_last (GSList *list)
|
||||
* Gets the number of elements in a #GSList.
|
||||
*
|
||||
* <note><para>
|
||||
* This function iterates over the whole list to
|
||||
* This function iterates over the whole list to
|
||||
* count its elements.
|
||||
* </para></note>
|
||||
*
|
||||
@ -846,8 +847,8 @@ g_slist_length (GSList *list)
|
||||
*/
|
||||
void
|
||||
g_slist_foreach (GSList *list,
|
||||
GFunc func,
|
||||
gpointer user_data)
|
||||
GFunc func,
|
||||
gpointer user_data)
|
||||
{
|
||||
while (list)
|
||||
{
|
||||
@ -859,15 +860,15 @@ g_slist_foreach (GSList *list,
|
||||
|
||||
static GSList*
|
||||
g_slist_insert_sorted_real (GSList *list,
|
||||
gpointer data,
|
||||
GFunc func,
|
||||
gpointer user_data)
|
||||
gpointer data,
|
||||
GFunc func,
|
||||
gpointer user_data)
|
||||
{
|
||||
GSList *tmp_list = list;
|
||||
GSList *prev_list = NULL;
|
||||
GSList *new_list;
|
||||
gint cmp;
|
||||
|
||||
|
||||
g_return_val_if_fail (func != NULL, list);
|
||||
|
||||
if (!list)
|
||||
@ -877,9 +878,9 @@ g_slist_insert_sorted_real (GSList *list,
|
||||
new_list->next = NULL;
|
||||
return new_list;
|
||||
}
|
||||
|
||||
|
||||
cmp = ((GCompareDataFunc) func) (data, tmp_list->data, user_data);
|
||||
|
||||
|
||||
while ((tmp_list->next) && (cmp > 0))
|
||||
{
|
||||
prev_list = tmp_list;
|
||||
@ -897,7 +898,7 @@ g_slist_insert_sorted_real (GSList *list,
|
||||
new_list->next = NULL;
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
if (prev_list)
|
||||
{
|
||||
prev_list->next = new_list;
|
||||
@ -915,11 +916,11 @@ g_slist_insert_sorted_real (GSList *list,
|
||||
* g_slist_insert_sorted:
|
||||
* @list: a #GSList
|
||||
* @data: the data for the new element
|
||||
* @func: the function to compare elements in the list.
|
||||
* It should return a number > 0 if the first parameter
|
||||
* @func: the function to compare elements in the list.
|
||||
* It should return a number > 0 if the first parameter
|
||||
* comes after the second parameter in the sort order.
|
||||
*
|
||||
* Inserts a new element into the list, using the given
|
||||
* Inserts a new element into the list, using the given
|
||||
* comparison function to determine its position.
|
||||
*
|
||||
* Returns: the new start of the #GSList
|
||||
@ -936,12 +937,12 @@ g_slist_insert_sorted (GSList *list,
|
||||
* g_slist_insert_sorted_with_data:
|
||||
* @list: a #GSList
|
||||
* @data: the data for the new element
|
||||
* @func: the function to compare elements in the list.
|
||||
* It should return a number > 0 if the first parameter
|
||||
* @func: the function to compare elements in the list.
|
||||
* It should return a number > 0 if the first parameter
|
||||
* comes after the second parameter in the sort order.
|
||||
* @user_data: data to pass to comparison function
|
||||
*
|
||||
* Inserts a new element into the list, using the given
|
||||
* Inserts a new element into the list, using the given
|
||||
* comparison function to determine its position.
|
||||
*
|
||||
* Returns: the new start of the #GSList
|
||||
@ -950,18 +951,18 @@ g_slist_insert_sorted (GSList *list,
|
||||
*/
|
||||
GSList*
|
||||
g_slist_insert_sorted_with_data (GSList *list,
|
||||
gpointer data,
|
||||
GCompareDataFunc func,
|
||||
gpointer user_data)
|
||||
gpointer data,
|
||||
GCompareDataFunc func,
|
||||
gpointer user_data)
|
||||
{
|
||||
return g_slist_insert_sorted_real (list, data, (GFunc) func, user_data);
|
||||
}
|
||||
|
||||
static GSList *
|
||||
g_slist_sort_merge (GSList *l1,
|
||||
GSList *l2,
|
||||
GFunc compare_func,
|
||||
gpointer user_data)
|
||||
g_slist_sort_merge (GSList *l1,
|
||||
GSList *l2,
|
||||
GFunc compare_func,
|
||||
gpointer user_data)
|
||||
{
|
||||
GSList list, *l;
|
||||
gint cmp;
|
||||
@ -974,57 +975,57 @@ g_slist_sort_merge (GSList *l1,
|
||||
|
||||
if (cmp <= 0)
|
||||
{
|
||||
l=l->next=l1;
|
||||
l1=l1->next;
|
||||
}
|
||||
else
|
||||
{
|
||||
l=l->next=l2;
|
||||
l2=l2->next;
|
||||
l=l->next=l1;
|
||||
l1=l1->next;
|
||||
}
|
||||
else
|
||||
{
|
||||
l=l->next=l2;
|
||||
l2=l2->next;
|
||||
}
|
||||
}
|
||||
l->next= l1 ? l1 : l2;
|
||||
|
||||
|
||||
return list.next;
|
||||
}
|
||||
|
||||
static GSList *
|
||||
g_slist_sort_real (GSList *list,
|
||||
GFunc compare_func,
|
||||
gpointer user_data)
|
||||
GFunc compare_func,
|
||||
gpointer user_data)
|
||||
{
|
||||
GSList *l1, *l2;
|
||||
|
||||
if (!list)
|
||||
if (!list)
|
||||
return NULL;
|
||||
if (!list->next)
|
||||
if (!list->next)
|
||||
return list;
|
||||
|
||||
l1 = list;
|
||||
l1 = list;
|
||||
l2 = list->next;
|
||||
|
||||
while ((l2 = l2->next) != NULL)
|
||||
{
|
||||
if ((l2 = l2->next) == NULL)
|
||||
break;
|
||||
if ((l2 = l2->next) == NULL)
|
||||
break;
|
||||
l1=l1->next;
|
||||
}
|
||||
l2 = l1->next;
|
||||
l2 = l1->next;
|
||||
l1->next = NULL;
|
||||
|
||||
return g_slist_sort_merge (g_slist_sort_real (list, compare_func, user_data),
|
||||
g_slist_sort_real (l2, compare_func, user_data),
|
||||
compare_func,
|
||||
user_data);
|
||||
g_slist_sort_real (l2, compare_func, user_data),
|
||||
compare_func,
|
||||
user_data);
|
||||
}
|
||||
|
||||
/**
|
||||
* g_slist_sort:
|
||||
* @list: a #GSList
|
||||
* @compare_func: the comparison function used to sort the #GSList.
|
||||
* This function is passed the data from 2 elements of the #GSList
|
||||
* and should return 0 if they are equal, a negative value if the
|
||||
* first element comes before the second, or a positive value if
|
||||
* This function is passed the data from 2 elements of the #GSList
|
||||
* and should return 0 if they are equal, a negative value if the
|
||||
* first element comes before the second, or a positive value if
|
||||
* the first element comes after the second.
|
||||
*
|
||||
* Sorts a #GSList using the given comparison function.
|
||||
@ -1033,7 +1034,7 @@ g_slist_sort_real (GSList *list,
|
||||
*/
|
||||
GSList *
|
||||
g_slist_sort (GSList *list,
|
||||
GCompareFunc compare_func)
|
||||
GCompareFunc compare_func)
|
||||
{
|
||||
return g_slist_sort_real (list, (GFunc) compare_func, NULL);
|
||||
}
|
||||
@ -1050,8 +1051,8 @@ g_slist_sort (GSList *list,
|
||||
*/
|
||||
GSList *
|
||||
g_slist_sort_with_data (GSList *list,
|
||||
GCompareDataFunc compare_func,
|
||||
gpointer user_data)
|
||||
GCompareDataFunc compare_func,
|
||||
gpointer user_data)
|
||||
{
|
||||
return g_slist_sort_real (list, (GFunc) compare_func, user_data);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user