1 .. title:: clang-tidy - performance-inefficient-string-concatenation
3 performance-inefficient-string-concatenation
4 ============================================
6 This check warns about the performance overhead arising from concatenating
7 strings using the ``operator+``, for instance:
11 std::string a("Foo"), b("Bar");
14 Instead of this structure you should use ``operator+=`` or ``std::string``'s
15 (``std::basic_string``) class member function ``append()``. For instance:
19 std::string a("Foo"), b("Baz");
20 for (int i = 0; i < 20000; ++i) {
24 Could be rewritten in a greatly more efficient way like:
28 std::string a("Foo"), b("Baz");
29 for (int i = 0; i < 20000; ++i) {
30 a.append("Bar").append(b);
33 And this can be rewritten too:
37 void f(const std::string&) {}
38 std::string a("Foo"), b("Baz");
43 In a slightly more efficient way like:
47 void f(const std::string&) {}
48 std::string a("Foo"), b("Baz");
50 f(std::string(a).append("Bar").append(b));
56 .. option:: StrictMode
58 When `false`, the check will only check the string usage in ``while``, ``for``
59 and ``for-range`` statements. Default is `false`.