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