Bug 158596

Summary: Introduce WTF::UniqueRef
Product: WebKit Reporter: Alex Christensen <achristensen>
Component: New BugsAssignee: Alex Christensen <achristensen>
Status: RESOLVED FIXED    
Severity: Normal CC: andersca, cdumez, darin, mitz, sam
Priority: P2    
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
Patch
none
Patch
none
Patch
none
Patch
none
Patch
none
Patch
none
Patch beidson: review+

Description Alex Christensen 2016-06-09 18:51:51 PDT
Introduce WTF::Unique
Comment 1 Alex Christensen 2016-06-09 19:10:28 PDT
Created attachment 280974 [details]
Patch
Comment 2 Alex Christensen 2016-06-09 19:16:21 PDT
Created attachment 280975 [details]
Patch
Comment 3 Alex Christensen 2016-06-09 20:20:34 PDT
Created attachment 280983 [details]
Patch
Comment 4 Darin Adler 2016-06-09 20:21:22 PDT
I like the idea of this class, but I’m not sure I’m comfortable with the name Unique.
Comment 5 Darin Adler 2016-06-09 20:21:41 PDT
Maybe UniqueRef by analogy with unique_ptr.
Comment 6 Alex Christensen 2016-06-09 22:09:09 PDT
Created attachment 280990 [details]
Patch
Comment 7 Alex Christensen 2016-06-09 22:21:56 PDT
Created attachment 280994 [details]
Patch
Comment 8 Alex Christensen 2016-06-09 23:26:05 PDT
Created attachment 280997 [details]
Patch
Comment 9 Alex Christensen 2016-06-09 23:55:43 PDT
Created attachment 280999 [details]
Patch
Comment 10 Michael Catanzaro 2016-06-10 05:36:18 PDT
Comment on attachment 280999 [details]
Patch

I see the point: you have to use something like std::unique_ptr here, and having a type to indicate it can never be null seems useful. I just wonder if the actual benefit would be worth the cost of having one more type of Ref to learn and understand. Probably; converting pointer member variables to refs elsewhere in the code has had big readability benefits. Shame there's no standard solution for this.

Agreed with Darin that the name is not good, a "unique ref" sounds like something that shouldn't be refcounted. It's hard to name though... "NonintrusiveRef" is not great, but it's the best I can think of. "NonnullUniquePtr" is awkward but clear. Alternatively we could try to think of a name that indicates its purpose for holding values of polymorphic type.
Comment 11 Alex Christensen 2016-06-10 14:24:41 PDT
http://trac.webkit.org/changeset/201941