This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Perl_sv_vcatpvfn_flags: simplify format appending
The bit at the end of the main loop has a whole bunch of conditionals
along the lines of
if (gap && !left)
apppend gap
if (esignlen && !fill)
append esignbuf
if (zeros)
append zeroes
if (elen)
append ebuf
if (gap && left)
append gap
This involves many tests along the main code path to cope with all the
possibilities (e.g. if left, gap is output before ebuf, otherwise after)
Instead split it into a couple of major branches with duplication between
the branches, but requiring few tests along any one code path.
For example, sprintf("%5d", -1) formerly required 9 branches, 1 for loop,
and 1 memset(). It now requires 2 branches and 3 for loops,
I've removed memset()s and replaced them with for loops. For the short
padding typically used (e.g. "%9d" rather than "%8192d") a loop is faster.