On Tue, Jun 30, 2015 at 1:58 PM, Jeff King <p...@peff.net> wrote:
> On Tue, Jun 30, 2015 at 12:58:33PM -0400, Eric Sunshine wrote:
>> Beyond the extra allocation, I was also concerned about the
>> sledgehammer approach of "%s " to append a single character when there
>> are much less expensive ways to do so.
>
> I don't think there's any other way. We have to feed a contiguous buffer
> to strftime, and we don't own the buffer, so we have to make a new copy.

Sorry, I meant that the interpolation expense of "%s ". A cheaper (but
more verbose) alternative might be:

    size_t n = strlen(fmt);
    const char *f = xmalloc(n + 2);
    strcpy(f, fmt);
    f[n] = ' ';
    f[n + 1] = '\0';
    ...
    free(f);

or something similar.
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to