]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Coding Guidelines: Mention reserve()/resize() explicitly, with links
authorRemi Gacogne <remi.gacogne@powerdns.com>
Wed, 16 Aug 2023 07:36:21 +0000 (09:36 +0200)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Wed, 16 Aug 2023 07:36:21 +0000 (09:36 +0200)
CODING_GUIDELINES.md

index 79e5623b100a1837fde58a3a7633081fc8ba25f8..64c2f8b1f11d79786cdb09c17038fd08119cc5ab 100644 (file)
@@ -227,8 +227,8 @@ The use of a container and its corresponding `at()` operator would have prevente
 The cost of using `at()` is negligible for most use cases, and can be avoided by using the `[]` operator in the rare case when the cost cannot be afforded.
 Note that several Linux distributions now build with `-Wp,-D_GLIBCXX_ASSERTIONS` enabled by default, which turns on cheap range checks for C++ arrays, vectors, and strings.
 
-Regarding performance, it is advised to `reserve()` the needed size in advance when a rough estimate is known to avoid reallocations and copies. It usually triggers the allocation of enough memory to hold the requested number of items but does not increase the size of the container as reported by `size()`.
-Resizing in advance is not advised, though, as it makes it harder to exactly know what is in the container in case of early returns or exceptions.
+Regarding performance, it is advised to [`reserve()`](https://en.cppreference.com/w/cpp/container/vector/reserve) the needed size in advance when a rough estimate is known to avoid reallocations and copies. It usually triggers the allocation of enough memory to hold the requested number of items but does not increase the size of the container as reported by `size()`.
+Calling [`resize()`](https://en.cppreference.com/w/cpp/container/vector/resize) in advance is not advised, though, as it makes it harder to exactly know what is in the container in case of early returns or exceptions.
 
 In C++11, move operators make it possible to cheaply get the contents of a container into a different variable if needed.