Warning, /sdk/clazy/docs/checks/README-qstring-allocations.md is written in an unsupported language. File is not indexed.

0001 # qstring-unneeded-heap-allocations
0002 
0003 Finds places with unneeded memory allocations due to temporary `QString`s.
0004 
0005 Here's a summary of usages that allocate:
0006 
0007 1. `QString s = "foo"; // Allocates, use QStringLiteral("foo") instead`
0008 
0009 2. `QString s = QLatin1String("foo"); // Allocates, use QStringLiteral("foo") instead`
0010 
0011     2.1 `QString s = QLatin1String(""); // No allocation. QString is optimized for this case, so it's safe for empty literals`
0012 
0013 3. `QString s = QStringLiteral("foo"); // No allocation`
0014 
0015 4. `QString s = QString::fromLatin1("foo"); // Allocates, use QStringLiteral`
0016 
0017 5. `QString s = QString::fromUtf8("foo"); // Allocates, use QStringLiteral`
0018 
0019 6. `s == "foo" // Allocates, use QLatin1String`
0020 
0021 7. `s == QLatin1String("foo") // No allocation`
0022 
0023 8. `s == QStringLiteral("foo") // No allocation`
0024 
0025 9. `QString {"append", "compare", "endsWith", "startsWith", "indexOf", "insert",`
0026    `         "lastIndexOf", "prepend", "replace", "contains" } // They all have QLatin1String overloads, so passing a QLatin1String is ok.`
0027 
0028 10. `QString::fromLatin1("foo %1").arg(bar) // Allocates twice, replacing with QStringLiteral makes it allocate only once.`
0029 
0030 
0031 #### Fixits
0032 
0033 This check supports a fixit to rewrite your code. See the README.md on how to enable it.
0034 
0035 #### Pitfalls
0036 
0037 - `QStringLiteral` might make your app crash at exit if plugins are involved.
0038 See:
0039 <https://blogs.kde.org/2015/11/05/qregexp-qstringliteral-crash-exit> and
0040 <http://lists.qt-project.org/pipermail/development/2015-November/023681.html>
0041 
0042 - Also note that MSVC crashes when `QStringLiteral` is used inside initializer lists. For that reason no warning or fixit is emitted for this case unless you set an env variable:
0043 
0044         export CLAZY_EXTRA_OPTIONS="qstring-allocations-no-msvc-compat"