>I searched the codes and found some other places where the manipulation
>of lists can be improved in a similar way.

>* lappend(list_copy(list), datum) as in get_required_extension().
>This is not very efficient as after list_copy it would need to enlarge
>the list immediately. It can be improved by inventing a new function,
>maybe called list_append_copy, that do the copy and append all together.

>* lcons(datum, list_copy(list)) as in get_query_def().
>This is also not efficient. Immediately after list_copy, we'd need to
>enlarge the list and move all the entries. It can also be improved by
>doing all these things all together in one function.

>* lcons(datum, list_delete_nth_cell(list_copy(list), n)) as in
>sort_inner_and_outer.
>It'd need to copy all the elements, and then delete the n'th entry which
>would cause all following entries be moved, and then move all the
>remaining entries for lcons. Maybe we can invent a new function for it?

>So is it worthwhile to improve these places?

I think yes. It's very inefficient coping and moving, unnecessarily.

Perhaps, like the attached patch?

lcons_copy_delete needs a careful review.


>I wonder if we can invent function list_nth_xid to do it, to keep
>consistent with list_nth/list_nth_int/list_nth_oid.

Perhaps list_nth_xid(const List *list, int n)?

regards,

Ranier Vilela

Attachment: 0001-add-new-list-functions.patch
Description: Binary data

Reply via email to