[webkit-dev] Get rid of RefPtr, replace with std::optional<Ref>?

Chris Dumez cdumez at apple.com
Fri Sep 1 10:09:15 PDT 2017


I think std::optional<Ref<Type>> looks ugly. Also, unlike RefPtr<>, I do not think it is copyable. It is pretty neat to be able to capture a RefPtr<> by value in a lambda.
Also, how do you convert it to a raw pointer? myOptionalRef.value_or(nullptr) would not work. Not sure there would be a nice way to do so.

Finally, the storage space argument from Maciej is a good one.
 
--
 Chris Dumez




> On Sep 1, 2017, at 9:46 AM, Maciej Stachowiak <mjs at apple.com> wrote:
> 
> 
> 
>> On Sep 1, 2017, at 9:30 AM, Brady Eidson <beidson at apple.com> wrote:
>> 
>> I recently worked on a patch where - because of the organic refactoring of the patch over its development - I ended up with a std::optional<Ref> instead of a RefPtr.
>> 
>> A followup review after it had already landed pointed this out, and it got me to thinking:
>> 
>> Does RefPtr do anything for us today that std::optional<Ref> doesn’t?
> 
> The obvious things would be: uses less storage space, has a shorter name.
> 
>> 
>> I kind of like the idea of replacing RefPtr with std::optional<Ref>. It makes it explicitly clear what object is actually holding the reference, and completely removes some of the confusion of “when should I use Ref vs RefPtr?"
>> 
>> Thoughts?
>> 
>> Thanks,
>> ~Brady
>> _______________________________________________
>> webkit-dev mailing list
>> webkit-dev at lists.webkit.org
>> https://lists.webkit.org/mailman/listinfo/webkit-dev
> 
> _______________________________________________
> webkit-dev mailing list
> webkit-dev at lists.webkit.org
> https://lists.webkit.org/mailman/listinfo/webkit-dev

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.webkit.org/pipermail/webkit-dev/attachments/20170901/2a9688ec/attachment.html>


More information about the webkit-dev mailing list