From e1ed24196b377452963f5183ed1d8f49af0cba32 Mon Sep 17 00:00:00 2001 From: Karl Wiberg Date: Wed, 6 Sep 2017 11:10:23 +0200 Subject: [PATCH] Style guide: Add guideline for ArrayView MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit BUG=none NOTRY=true Change-Id: I25ac7da349246f6bf1441200f2a2136218e30591 Reviewed-on: https://chromium-review.googlesource.com/648982 Commit-Queue: Karl Wiberg Reviewed-by: Niels Möller Reviewed-by: Danil Chapovalov Cr-Commit-Position: refs/heads/master@{#19711} --- style-guide.md | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/style-guide.md b/style-guide.md index e10b1a8ead..b39ab35fe1 100644 --- a/style-guide.md +++ b/style-guide.md @@ -3,9 +3,9 @@ ## C++ WebRTC follows the [Chromium][chr-style] and [Google][goog-style] C++ -style guides, unless an exception is listed below. In cases where they -conflict, the Chromium style guide trumps the Google style guide, and -the exceptions in this file trump them both. +style guides. In cases where they conflict, the Chromium style guide +trumps the Google style guide, and the rules in this file trump them +both. [chr-style]: https://chromium.googlesource.com/chromium/src/+/master/styleguide/c++/c++.md [goog-style]: https://google.github.io/styleguide/cppguide.html @@ -18,10 +18,21 @@ Some older parts of the code violate the style guide in various ways. * If making large changes to such code, consider first cleaning it up in a separate CL. -### Exceptions +### ArrayView -There are no exceptions yet. If and when exceptions are adopted, -they’ll be listed here. +When passing an array of values to a function, use `rtc::ArrayView` +whenever possible—that is, whenever you’re not passing ownership of +the array, and don’t allow the callee to change the array size. + +For example, + +instead of | use +------------------------------------|--------------------- +`const std::vector&` | `ArrayView` +`const T* ptr, size_t num_elements` | `ArrayView` +`T* ptr, size_t num_elements` | `ArrayView` + +See [the source](webrtc/api/array_view.h) for more detailed docs. ## C