From b3f7dbc7a5ce05f57958c23f4ca7fff09d24a66d Mon Sep 17 00:00:00 2001 From: kwiberg Date: Tue, 10 Jan 2017 02:11:17 -0800 Subject: [PATCH] Add advice about Optional function arguments This comes from here: https://codereview.webrtc.org/2585293002/diff/1/webrtc/modules/audio_coding/audio_network_adaptor/fec_controller.h#newcode91 BUG=none NOTRY=true Review-Url: https://codereview.webrtc.org/2624573004 Cr-Commit-Position: refs/heads/master@{#15980} --- webrtc/base/optional.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/webrtc/base/optional.h b/webrtc/base/optional.h index ec33470f26..4d2b44e0cb 100644 --- a/webrtc/base/optional.h +++ b/webrtc/base/optional.h @@ -77,6 +77,12 @@ inline T* FunctionThatDoesNothing(T* x) { return x; } // might make sense, but any larger parse job is probably going to need to // tell the caller what the problem was, not just that there was one. // +// - As a non-mutable function argument. When you want to pass a value of a +// type T that can fail to be there, const T* is almost always both fastest +// and cleanest. (If you're *sure* that the the caller will always already +// have an Optional, const Optional& is slightly faster than const T*, +// but this is a micro-optimization. In general, stick to const T*.) +// // TODO(kwiberg): Get rid of this class when the standard library has // std::optional (and we're allowed to use it). template