glist: Clarify that g_list_nth() is expensive

Just in case people have forgotten their basic algorithms course. Seen
in some pretty terrible code in the wild; hopefully mentioning the cost
in the documentation will make people think twice about using a counter
variable when iterating over a linked list.

https://bugzilla.gnome.org/show_bug.cgi?id=741779
This commit is contained in:
Philip Withnall 2014-12-19 18:53:54 +00:00
parent c6312daba0
commit 984576c01e

View File

@ -733,6 +733,10 @@ g_list_reverse (GList *list)
*
* Gets the element at the given position in a #GList.
*
* This iterates over the list until it reaches the @n-th position. If you
* intend to iterate over every element, it is better to use a for-loop as
* described in the #GList introduction.
*
* Returns: the element, or %NULL if the position is off
* the end of the #GList
*/
@ -773,6 +777,10 @@ g_list_nth_prev (GList *list,
*
* Gets the data of the element at the given position.
*
* This iterates over the list until it reaches the @n-th position. If you
* intend to iterate over every element, it is better to use a for-loop as
* described in the #GList introduction.
*
* Returns: the element's data, or %NULL if the position
* is off the end of the #GList
*/