[Rpm-maint] [PATCH 2/5] Reimplemented argvJoin function
Panu Matilainen
pmatilai at laiskiainen.org
Fri Feb 8 14:45:38 UTC 2013
On 02/05/2013 06:31 AM, Alexey Tourbin wrote:
> Joining lines with consecutive rstrscat() calls was bad idea, because,
> to append n-th argument, rstrscat() first has to calculate the length
> of its previous result, that is, in a sense, the length of all its (n-1)
> arguments. Thus the complexity was O(n^2), due to arithmetic progression.
Yes, very well known at the time of implementing it :) Here too, the
idea always was to just stuff in something that works and optimize later
if it actually turns out to be an issue.
> This change introduces a highly optimized version of argvJoin. In
> particular, strlen() call for each argv element is issued only once.
> Also, the inner loop is tuned for the special case of empty or
> single-character separator, to avoid extra memcpy per-element call.
I'd actually much rather see a simpler variant which just does away with
the O(n^2) behavior in the most straightforward manner possible. This
isn't IMO anywhere near critical enough function to warrant extra
complexity just to shave out a few cycles on special cases.
- Panu -
More information about the Rpm-maint
mailing list