Bug 121154 - OwnPtr: Use copy/move-and-swap for assignment operators
Summary: OwnPtr: Use copy/move-and-swap for assignment operators
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Web Template Framework (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Mikhail Pozdnyakov
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-09-11 05:17 PDT by Mikhail Pozdnyakov
Modified: 2013-09-11 07:32 PDT (History)
6 users (show)

See Also:


Attachments
patch (2.36 KB, patch)
2013-09-11 06:33 PDT, Mikhail Pozdnyakov
andersca: review+
andersca: commit-queue-
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Mikhail Pozdnyakov 2013-09-11 05:17:57 PDT
Rationals:
- decrease of repeated code
- consistency with RefPtr
Comment 1 Mikhail Pozdnyakov 2013-09-11 06:33:59 PDT
Created attachment 211306 [details]
patch
Comment 2 Anders Carlsson 2013-09-11 07:17:16 PDT
Comment on attachment 211306 [details]
patch

View in context: https://bugs.webkit.org/attachment.cgi?id=211306&action=review

> Source/WTF/wtf/OwnPtr.h:140
> -        PtrType ptr = m_ptr;
> -        m_ptr = o.leakPtr();
> -        ASSERT(!ptr || m_ptr != ptr);
> -        deleteOwnedPtr(ptr);
> +        ASSERT(!o || o != m_ptr);
> +        OwnPtr ptr = o;
> +        swap(ptr);

I wouldn't worry about modifying PassOwnPtr since then plan is to get rid of it.

> Source/WTF/wtf/OwnPtr.h:148
> -        PtrType ptr = m_ptr;
> -        m_ptr = o.leakPtr();
> -        ASSERT(!ptr || m_ptr != ptr);
> -        deleteOwnedPtr(ptr);
> +        ASSERT(!o || o != m_ptr);
> +        OwnPtr ptr = o;
> +        swap(ptr);

Ditto.

> Source/WTF/wtf/OwnPtr.h:166
> +        OwnPtr ptr = std::move(o);

Can just use auto here.

> Source/WTF/wtf/OwnPtr.h:174
> +        OwnPtr ptr = std::move(o);

Ditto.
Comment 3 Mikhail Pozdnyakov 2013-09-11 07:32:22 PDT
Committed r155526: <http://trac.webkit.org/changeset/155526>