CODING_STYLE: fix rules for STRLEN and recommend strjoina more strongly

Again, this mostly matches what is happening in the codebase already.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek 2018-11-19 13:24:34 +01:00
parent a527f70a41
commit a98dc693e4
1 changed files with 9 additions and 5 deletions

View File

@ -373,12 +373,16 @@
something some time", or so is a lazy excuse. Always wait for the something some time", or so is a lazy excuse. Always wait for the
proper event, instead of doing time-based poll loops. proper event, instead of doing time-based poll loops.
- To determine the length of a constant string `"foo"`, don't bother - To determine the length of a constant string `"foo"`, don't bother with
with `sizeof("foo")-1`, please use `STRLEN()` instead. `sizeof("foo")-1`, please use `strlen()` instead (both gcc and clang optimize
the call away for fixed strings). The only exception is when declaring an
array. In that case use STRLEN, which evalutates to a static constant and
doesn't force the compiler to create a VLA.
- If you want to concatenate two or more strings, consider using - If you want to concatenate two or more strings, consider using `strjoina()`
`strjoin()` rather than `asprintf()`, as the latter is a lot or `strjoin()` rather than `asprintf()`, as the latter is a lot slower. This
slower. This matters particularly in inner loops. matters particularly in inner loops (but note that `strjoina()` cannot be
used there).
- Please avoid using global variables as much as you can. And if you - Please avoid using global variables as much as you can. And if you
do use them make sure they are static at least, instead of do use them make sure they are static at least, instead of