Bug 1349379 - Clarify when to use already_AddRefed. - r=dbaron,waldo draft
authorJeff Gilbert <jgilbert@mozilla.com>
Tue, 21 Mar 2017 16:00:34 -0700
changeset 503835 02f81abae18d4c895947dfce178e039e21a1787d
parent 500973 67162d27979c8e8dbbc81461b5915e6ac15683d9
child 550516 c28f95346688e7a71650d2de1afb9349439dcdf4
push id50670
push userbmo:jgilbert@mozilla.com
push dateThu, 23 Mar 2017 16:26:22 +0000
reviewersdbaron, waldo
bugs1349379
milestone55.0a1
Bug 1349379 - Clarify when to use already_AddRefed. - r=dbaron,waldo MozReview-Commit-ID: 2MlOhirdzlQ
mfbt/AlreadyAddRefed.h
--- a/mfbt/AlreadyAddRefed.h
+++ b/mfbt/AlreadyAddRefed.h
@@ -22,16 +22,24 @@ struct unused_t;
 /**
  * already_AddRefed cooperates with reference counting smart pointers to enable
  * you to assign in a pointer _without_ |AddRef|ing it.  You might want to use
  * this as a return type from a function that returns an already |AddRef|ed
  * pointer.
  *
  * TODO Move already_AddRefed to namespace mozilla.  This has not yet been done
  * because of the sheer number of usages of already_AddRefed.
+ *
+ * When should you use already_AddRefed<>?
+ * * Ensure a consumer takes ownership of a reference
+ * * Pass ownership without calling AddRef/Release (sometimes required in
+ *   off-main-thread code)
+ * * The ref pointer type you're using doesn't support move construction
+ *
+ * Otherwise, use Move(RefPtr/nsCOMPtr/etc).
  */
 template<class T>
 struct MOZ_MUST_USE_TYPE MOZ_NON_AUTOABLE already_AddRefed
 {
   /*
    * We want to allow returning nullptr from functions returning
    * already_AddRefed<T>, for simplicity.  But we also don't want to allow
    * returning raw T*, instead preferring creation of already_AddRefed<T> from