HomeClusterLabs Projects

Refactor: libcrmcommon: best practices for pcmk__replace_submatches()

Description

Refactor: libcrmcommon: best practices for pcmk__replace_submatches()

Previously, pcmk__replace_submatches() had two nearly identical loops,
the first to determine the expanded string size, and the second to do the
expansion.

However, their handling of a non-match or empty match was different, causing
the memory to be slightly overallocated in that case. To avoid this and any
future differences, this functionizes that loop so differences are minimized.

In addition, the new implementation short-circuits if there were no expansions,
rather than allocate a string identical to the input. All callers already
handle this appropriately.

Details

Provenance
kgaillotAuthored on Mar 7 2024, 1:25 PM
Parents
rP6aa7def00713: Test: libcrmcommon: add unit tests for pcmk__replace_submatches()
Branches
Unknown
Tags
Unknown