[PATCH v1 1/7] libiberty: add helper to swap doubly-linked list wrappers

Matthieu Longo matthieu.longo@arm.com
Tue Feb 3 10:09:23 GMT 2026


On 03/02/2026 10:00, Matthieu Longo wrote:
> This patch introduces a new helper to swap the contents of two
> doubly-linked list wrappers. The new *_swap_lists operation exchanges
> the first, last, and size fields, allowing two lists to be swapped
> efficiently without iterating over their elements.
> 
> This helper is intended for cases where the ownership of a list must be
> exchanged but swapping wrapper pointers is not possible. For simple
> references to lists, when wrappers are dynamically allocated, swapping
> the wrapper pointers themselves is sufficient and remains the preferred
> approach.
> 
> This change adds the necessary declaration and definition macros to
> doubly-linked-list.h and integrates them into the set of mutative
> list operations.
> 
> The testsuite is updated accordingly to cover the new functionality.
> 
> include/ChangeLog:
> 
> 	* doubly-linked-list.h
> 	(LINKED_LIST_SWAP_LISTS): Add new helper.
> 	(LINKED_LIST_DECL_SWAP_LISTS): Likewise.
> 	(LINKED_LIST_DEFN_SWAP_LISTS): Likewise.
> 	(LWRAPPERTYPE##_swap_lists): Likewise.
> 
> libiberty/ChangeLog:
> 
> 	* testsuite/test-doubly-linked-list.c: Update.

Please note that I already sent this patch to the GCC mailing list, and plan to merge the patch there first.

https://inbox.sourceware.org/gcc-patches/20260130171757.3326475-1-matthieu.longo@arm.com/

Matthieu


More information about the Binutils mailing list