Re: [PATCH] clean: use warning_errno() when appropriate
- From
Jeff King <peff@peff.net>
- Date
- Feb 13, 2017, 21:10 UTC
- Message-ID
- <20170213211051.vsnnrtcsvuvfcwyk@sigill.intra.peff.net>
- In-Reply-To
- <xmqqk28tddwo.fsf@gitster.mtv.corp.google.com>
On Mon, Feb 13, 2017 at 12:38:47PM -0800, Junio C Hamano wrote:
Show 11 quoted lines
> Jeff King <peff@peff.net> writes: > > > I wonder if xmalloc() should be the one doing the saved_errno trick. > > After all, it has only two outcomes: we successfully allocated the > > memory, or we called die(). > > I would be lying if I said I did not considered it when I wrote the > message you are responding to, but I rejected it because that would > be optimizing for a wrong case, in that most callers of xmalloc() > and friends do not do so in the error codepath, and we would be > penalizing them by doing the saved_errno dance unconditionally.
Yes, that also occurred to me. I'm not sure if two integer swaps is enough to care about when compared to the cost of a malloc(), though.
IOW, I think this may be a case where we should be optimizing for programmer time (fewer lines of code, and one less thing to worry about in the callers) versus squeezing out every instruction.
-Peff