Commit 4b661e4
tidy: enable performance checks
With the exception of performance-no-int-to-ptr, this change enables
clang tidy's performance-based lints.
The changes made are as follows, in no particular order.
- Avoid std::endl. std::endl is confusing because it also flushes the
buffer, which is often undesirable. Instead, we should just use a newline
character.
- When possible, declare variables as `const T&` instead of `T`, since
it avoids a copy.
- When possible, use `std::move` to avoid a copy. However, if the type
is trivially copyable, `std::move` does nothing and hence should be
removed. Furthermore, if the variable to be moved is constant,
`std::move` simply copies, and so `std::move` is confusing and should
be removed. Finally, if the variable is moved, but the function
parameter type is `const T&`, then a move is unnecessary, and again,
it should be removed.
- When using `push_back` in a loop, we should reserve up front for
better performance.
- When concatenating strings, either we should `std::move()` the
strings, or use `string::append`. Otherwise, we pay the price of
creating temporary strings, instead of just pushing to a single
string.
- Trivial destructors should be declared with `= default` to allow more
aggressive compiler optimizations.1 parent 9f24b07 commit 4b661e4
1 file changed
Lines changed: 3 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
| 4 | + | |
3 | 5 | | |
4 | 6 | | |
5 | 7 | | |
| |||
64 | 66 | | |
65 | 67 | | |
66 | 68 | | |
67 | | - | |
| 69 | + | |
68 | 70 | | |
69 | 71 | | |
70 | 72 | | |
| |||
0 commit comments