Improved performance of twc_list_get.
Walk the list backwards if we're getting an index closer to the end than the beginning.
This commit is contained in:
parent
666dd36f8d
commit
ffc381b869
@ -174,10 +174,19 @@ twc_list_get(struct t_twc_list *list, size_t index)
|
||||
|
||||
size_t current_index;
|
||||
struct t_twc_list_item *item;
|
||||
if (list->count - index > index / 2)
|
||||
{
|
||||
twc_list_foreach(list, current_index, item)
|
||||
{
|
||||
if (current_index == index)
|
||||
return item;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
twc_list_foreach_reverse(list, current_index, item)
|
||||
{
|
||||
if (current_index == index)
|
||||
return item;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user