]> git.ipfire.org Git - thirdparty/systemd.git/commit - src/basic/strv.c
strv: when growing strv arrays piecemeal actually allocate memory in exponential... 14295/head
authorLennart Poettering <lennart@poettering.net>
Mon, 9 Dec 2019 17:30:00 +0000 (18:30 +0100)
committerLennart Poettering <lennart@poettering.net>
Mon, 9 Dec 2019 17:36:03 +0000 (18:36 +0100)
commit6047637645ac8038edbca12bf91d030eddd59972
treefc3566ca48276d021861da6412aedb7faf10cd10
parent47ac31f792a8856f29ea4ac38d6b366e88ac7d34
strv: when growing strv arrays piecemeal actually allocate memory in exponential steps

Let's improve memory allocation for call such as strv_extend() that just
one item to an strv: these are often called in a loop, where they used
to be very ineffecient, since we'd allocate byte-exact space. With this
change let's improve on that, by allocating exponentially by rounding up
to the next exponent of 2. This way we get GREEDY_REALLOC()-like
behaviour without passing around state.

In fact this should be good enough so that we could replace existing
loops around GREEDY_REALLOC() for strv build-up with plain strv_extend()
and get similar behaviour.
src/basic/strv.c