[Webkit-unassigned] [Bug 73683] KeyframeValueList::operator= is neither safe to use nor prohibited

bugzilla-daemon at webkit.org bugzilla-daemon at webkit.org
Mon Dec 5 13:32:35 PST 2011


https://bugs.webkit.org/show_bug.cgi?id=73683





--- Comment #10 from Yong Li <yong.li.webkit at gmail.com>  2011-12-05 13:32:35 PST ---
(In reply to comment #9)
> (From update of attachment 117892 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=117892&action=review
> 
> > Source/WebCore/platform/graphics/GraphicsLayer.h:182
> > +    KeyframeValueList& operator=(const KeyframeValueList& o)
> > +    {
> > +        if (this == &o)
> > +            return *this;
> > +
> > +        this->~KeyframeValueList();
> > +        new (this) KeyframeValueList(o);
> > +        return *this;
> > +    }
> 
> The copy and swap idiom is usually preferred over this idiom. I’d like to use that instead.

Copy and swap performs one more copy if not optimized by compiler, and it also needs a swap method. It is first time I got the dtor/copy ctor idiom when writing operator=, and I love it immediately. I even hope it could be a standard that all c++ compilers should implicitly implement operator= in this way when a copy ctor is available: destruct the object and copy-construct a new one on the zombie.

One of the pros of the copy and swap idiom is it doesn't need to check (this == &o) assuming swap() already checks that.

Also, I cannot find any "new (this)" in current webkit code, which may a little bit tricky. So I'll upload a copy&swap version.

-- 
Configure bugmail: https://bugs.webkit.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.


More information about the webkit-unassigned mailing list