You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
can lead to at most two allocations in most implementations (new string created for a + "Bar", then b is concatenated using rvalue-overload of operator+, which is equivalent to append), whilst the second one can lead to three allocations (copy of a is created, and then both append calls might lead to reallocation).
Maybe this transformation made sense before C++11, but nowadays it seems that only assignments of form a = [... + ]a + ... are in fact suboptimal.
The text was updated successfully, but these errors were encountered:
loskutov
changed the title
[clang-tidy] performance-inefficient-string-concatenation: slm
[clang-tidy] performance-inefficient-string-concatenation: sometimes code complained to is optimal
Mar 24, 2022
The first example is really not quite good. There is the "small string optimization", so strings have to be 16+ chars long (on most machines) to provoke any memory allocations. Seems like the check behaves like there is no such optimization.
The check description states that
can be rewritten "in a slightly more efficient way" like:
In fact, the first version:
a + "Bar"
, thenb
is concatenated using rvalue-overload ofoperator+
, which is equivalent toappend
), whilst the second one can lead to three allocations (copy ofa
is created, and then bothappend
calls might lead to reallocation).Maybe this transformation made sense before C++11, but nowadays it seems that only assignments of form
a = [... + ]a + ...
are in fact suboptimal.The text was updated successfully, but these errors were encountered: