Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(58)

Issue 2084893002: Implement scoped_const_refptr template. (Closed)

Created:
4 years, 6 months ago by nisse-webrtc
Modified:
4 years, 2 months ago
CC:
webrtc-reviews_webrtc.org, tterriberry_mozilla.com, zhuangzesen_agora.io, danilchap, stefan-webrtc, mflodman
Base URL:
https://chromium.googlesource.com/external/webrtc.git@master
Target Ref:
refs/pending/heads/master
Project:
webrtc
Visibility:
Public.

Description

Implement scoped_const_refptr template. The objectives of this hack are: 1. To make it possible to make good use of use const for refcounted arguments that are not modified by the method/function. 2. Keep using the const scoped_refptr<Type>& style, to avoid refcount updates for the call, but extend it const-declare the referred-to object. 3. Not impose any additional storage or runtime overhead. 4. Make it possible to pass a |const scoped_refptr<Type>&| to a function expecting a |const scoped_const_refptr<Type>&|, with automatic type conversion, and *without* constructing any temporary object. The last requirement is the tricky one. It looks easy to just use |const scoped_refptr<const Type>&|, but as far as I understand, this would require a new temporary object and corersponding refcount updates. The only way I've found (suggested by perkj) to get automatic conversion and pass a reference to the same ptr object, is to introduce scoped_const_refptr as a base class of scoped_ref_ptr. And then requirement (3) implies that the sub class scoped_refptr must use the same pointer member as the base class, using some ugly but safe const casts. All comments appreciated. It's not a really pure and kosher hack, but I think the benefit, of being able to mark ref counted arguments as const where appropriate, may be worth it. Also note that for this to work, AddRef and Release most be const methods, and the actual refcount declared as mutable. That's already fixed for the main RefCountedObject base class, but needed some fixes for older code. As an initial test of the code, it is used for the source arguments to some of the I420Buffer methods. BUG=

Patch Set 1 #

Unified diffs Side-by-side diffs Delta from patch set Stats (+101 lines, -42 lines) Patch
M webrtc/base/bind_unittest.cc View 1 chunk +3 lines, -3 lines 0 comments Download
M webrtc/base/scoped_ref_ptr.h View 2 chunks +79 lines, -21 lines 0 comments Download
M webrtc/common_video/include/video_frame_buffer.h View 2 chunks +5 lines, -5 lines 0 comments Download
M webrtc/common_video/video_frame_buffer.cc View 4 chunks +6 lines, -5 lines 0 comments Download
M webrtc/modules/desktop_capture/x11/shared_x_display.h View 2 chunks +3 lines, -3 lines 0 comments Download
M webrtc/modules/rtp_rtcp/source/forward_error_correction.h View 1 chunk +3 lines, -3 lines 0 comments Download
M webrtc/modules/rtp_rtcp/source/forward_error_correction.cc View 1 chunk +2 lines, -2 lines 0 comments Download

Messages

Total messages: 6 (1 generated)
nisse-webrtc
This is an experimental cl to make it possible to improve const type checking for ...
4 years, 6 months ago (2016-06-21 10:24:07 UTC) #2
kwiberg-webrtc
On 2016/06/21 10:24:07, nisse-webrtc (ooo August 15) wrote: > This is an experimental cl to ...
4 years, 4 months ago (2016-08-11 13:45:12 UTC) #3
nisse-webrtc
On 2016/08/11 13:45:12, kwiberg-webrtc wrote: > they really ought to pass e.g. T* or const ...
4 years, 4 months ago (2016-08-15 07:33:29 UTC) #4
kwiberg-webrtc
On 2016/08/15 07:33:29, nisse-webrtc (ooo August 15) wrote: > On 2016/08/11 13:45:12, kwiberg-webrtc wrote: > ...
4 years, 4 months ago (2016-08-15 07:41:02 UTC) #5
nisse-webrtc
4 years, 2 months ago (2016-09-26 08:31:33 UTC) #6
I'm closing this cl. Style guide now discourages use of pointers and references
to smart pointers
(https://www.chromium.org/developers/smart-pointer-guidelines), and then I think
we can just use scoped_refptr<const T> wherever appropriate. 

May still be relevant to change AddRef and Release to be const methods
everywhere, but that can be changed one place at a time when needed.

Powered by Google App Engine
This is Rietveld 408576698