On Tue, Nov 09, 2021 at 07:27:12PM +0000, Richard W.M. Jones wrote:
On Tue, Nov 09, 2021 at 08:53:28PM +0200, Nir Soffer wrote:
> I would try to extract the code to compute the new capacity into a helper
> function:
>
> if (next_capacity(v-cap, n, itemsize, &newcap))
> return -1;
>
> This function can return early instead of jumping around or fail
> if we cannot reserve n items. In the worst case this function will
> only hide the overflow macros.
OK
While I think this is a good idea, when I tried to make it work the
function wasn't very elegant. The problem is trying to make the
output "atomic", ie. only updating *newcap once.
What was worse, reading the disassembly Clang managed to produce
something that was less efficient, even though it inlined the function.
Rich.
--
Richard Jones, Virtualization Group, Red Hat
http://people.redhat.com/~rjones
Read my programming and virtualization blog:
http://rwmj.wordpress.com
virt-builder quickly builds VMs from scratch
http://libguestfs.org/virt-builder.1.html