[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Issue XXXX: Clean up to_string () etc. (issue 583320043 by address@h

From: lemzwerg
Subject: Re: Issue XXXX: Clean up to_string () etc. (issue 583320043 by address@hidden)
Date: Sat, 11 Jan 2020 23:44:42 -0800

s += EXTSEP; // append a char to s
s += ext_; // append a string to s

— vs. —

s += EXTSEP + ext_;
      make a string
  append it to s

Either one could involve memory allocation, but I deemed it more
likely in the latter case.  I don't have reason to suspect this is a
performance bottlenck, but given that I had to touch the line, and
that it wasn't a major rewrite, I decided to try to improve it.

I'm not sure that it is an improvement.  Today, compilers use very good
optimization tools; I can imagine that the performance of both lines is
exactly the same – or that the one-line version performs even better
since the compiler can handle the memory allocation internally in an
optimized way.  Only a profiler can give a clear answer, and this is
most certainly dependent on the platform and the compiler.

I thus favor code that is easiest to understand by the user, or which
looks nice.  Normally, I very much favor a vertical flow of source code,
but in this particular case the compact one-liner looks easier to

reply via email to

[Prev in Thread] Current Thread [Next in Thread]