Last night bug 1116905 (remove implicit conversions from T* to
TemporaryRef<T>) and bug 1160485 (remove implicit conversions from
RefPtr<T> to TemporaryRef<T>) landed on inbound.  Both of these changes
bring TemporaryRef more inline with already_AddRefed, and pave the way for
removing TemporaryRef entirely in favor of already_AddRefed (bug 1161627).

Fixing your code to deal with the first change is generally a matter of
adding a temporary RefPtr<T> variable to make the conversion explicit.  For
the reasonably common case of a function like:

TemporaryRef<T>
f(...)
{
   return new T(...);
}

One can use the newly-added MakeAndAddRef:

TemporaryRef<T>
f(...)
{
  return MakeAndAddRef<T>(...);
}

Fixing code to deal with the latter case is usually done by adding an
explicit .forget() call, which is also more efficient than the implicit
conversion, since it avoids an AddRef/Release pair.  A temporary RefPtr<T>
variable may be needed in cases which were previously written as:

TemporaryRef<T>
Class::GetMember()
{
  return mMember; // mMember is of type RefPtr<T>
}

We've had proposals for a do_AddRef(T*) -> already_AddRefed<T> utility
function for eliminating boilerplate-y nsRefPtr<T> variables; adding a
similar one (or an overload) for eliminating the temporary RefPtr<T>
variables required by these changes would be reasonable.

Thanks,
-Nathan
_______________________________________________
dev-platform mailing list
dev-platform@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-platform

Reply via email to