diff options
author | Thomas Haller <thaller@redhat.com> | 2019-04-05 22:44:49 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2019-04-09 20:43:34 +0200 |
commit | 26061f50c2b9a3fae1bd72a1fb489d3791524a71 (patch) | |
tree | a43b3a1d59179948e6838b343a78a6e4de8885fe /shared/nm-dispatcher-api.h | |
parent | 8ec40e3d875f46dc969b742adc6551134dd54e61 (diff) | |
download | NetworkManager-th/strsplit.tar.gz |
shared: pre-calculate number of tokens in nm_utils_strsplit_set_full()th/strsplit
Instead of growing the buffer for the tokens (and reallocating),
do one pre-run over the string and count the delimiters. This
way we know how much space we need and we don't need to
reallocate.
Interestingly, this is notably slower than the previous implementation,
because previously if would not bother determining the right number of
tokens but just over-allocate with a reasonable guess of 8 and grow the
buffer exponentially. Still, I like this better because while it may
be slower in common scenarios, it allocates the exact number of buffer
space.
Diffstat (limited to 'shared/nm-dispatcher-api.h')
0 files changed, 0 insertions, 0 deletions