CODING_STYLE: fix rules for STRLEN and recommend strjoina more strongly
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Mon, 19 Nov 2018 12:24:34 +0000 (13:24 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 20 Nov 2018 06:27:37 +0000 (07:27 +0100)
Again, this mostly matches what is happening in the codebase already.

docs/CODING_STYLE.md

index abcdaab4acac32e57e93d9d9c67d340a0f728491..e70c56b766bbe5319fc38a304db378750b495c83 100644 (file)
   something some time", or so is a lazy excuse. Always wait for the
   proper event, instead of doing time-based poll loops.
 
-- To determine the length of a constant string `"foo"`, don't bother
-  with `sizeof("foo")-1`, please use `STRLEN()` instead.
-
-- If you want to concatenate two or more strings, consider using
-  `strjoin()` rather than `asprintf()`, as the latter is a lot
-  slower. This matters particularly in inner loops.
+- To determine the length of a constant string `"foo"`, don't bother with
+  `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 `strjoina()`
+  or `strjoin()` rather than `asprintf()`, as the latter is a lot slower. This
+  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
   do use them make sure they are static at least, instead of