[webkit-dev] Terminology for giving up ownership: take, release, move
mjs at apple.com
Tue Sep 6 18:43:05 PDT 2016
> On Sep 6, 2016, at 5:27 PM, Darin Adler <darin at apple.com> wrote:
>> On Sep 6, 2016, at 4:48 PM, Maciej Stachowiak <mjs at apple.com> wrote:
>> STL smart pointers have a 0-argument reset for non-returning remove instead, and convention seems to be to use swap() or move() for the returning remove on a smart pointer. So an alternate possibility would be to use the above convention for collections, but make smart pointers have no remove+get operation at all.
> Our modern smart pointers follow the standard library convention you mention above.
> It’s the peculiar cases that need names, such as:
> “assert this RefPtr is non-null to turn it into a Ref&&”, currently named releaseNonNull
RefPtr does also have regular release() though. I'm not sure if this is for a practical reason or just no one has fixed it yet.
I am not sure about the non-null case. A wacky solution, based on your suggestion for releaseImpl, would be to have a nonNull method which asserts the pointer is not null and then returns a self reference, so you'd do move(ref.nonNull()).
> “release the RefPtr inside the String”, currently named releaseImpl(), but another possibility would be to have impl() be RefPtr<StringImpl>& instead of a StringImpl*, so you could do move(string.impl()) instead of string.releaseImpl().
That seems pretty reasonable.
More information about the webkit-dev