Bug 136934 - Add a move operator and constructor override to HashSet
Summary: Add a move operator and constructor override to HashSet
Status: NEW
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebCore Misc. (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Nobody
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-09-18 16:56 PDT by Roger Fong
Modified: 2014-09-19 10:54 PDT (History)
3 users (show)

See Also:


Attachments
patch (2.92 KB, patch)
2014-09-18 17:03 PDT, Roger Fong
no flags Details | Formatted Diff | Diff
patch (2.99 KB, patch)
2014-09-18 18:01 PDT, Roger Fong
no flags Details | Formatted Diff | Diff
patch (2.88 KB, patch)
2014-09-18 18:53 PDT, Roger Fong
darin: review-
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Roger Fong 2014-09-18 16:56:22 PDT
We do this to ensure that the Hashtable fields are zero'ed out when performing a move operation.
fast\dom\html-collections-named-getter.html fails in debug builds without this do a failing assertion that a hashset is empty.
Comment 1 Roger Fong 2014-09-18 17:03:58 PDT
Created attachment 238337 [details]
patch
Comment 2 Roger Fong 2014-09-18 18:01:30 PDT
Created attachment 238342 [details]
patch
Comment 3 Roger Fong 2014-09-18 18:53:00 PDT
Created attachment 238347 [details]
patch
Comment 4 Darin Adler 2014-09-19 08:53:40 PDT
Comment on attachment 238347 [details]
patch

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

review- because the EWS compiles failed; I think you are on the right track here, though

> Source/WTF/wtf/HashSet.h:114
> +        HashSet(HashSet&&);
> +        HashSet& operator=(HashSet&&);

We need to add regression tests for this. The file Tools/TestWebKitAPI/Tests/WTF/HashSet.cpp already exists, so we should add tests to it. It should not be hard to test that the set moved from ends up empty and the set moved to ends up with the appropriate contents.

I would have expected that adding these should not have been necessary because HashTable class already has a move constructor and assignment operator, but perhaps there’s something I’m missing. That test will really clear up the mystery.

> Source/WTF/wtf/HashSet.h:315
> +    template<typename Value, typename HashFunctions, typename Traits>
> +    inline HashSet<typename Value, typename HashFunctions, typename Traits>::HashSet(HashSet&& other)
> +    {
> +        swap(other);
> +    }

This should instead be:

    ...
        : m_impl(WTF::move(other.m_impl))
    {
    }

The swap function does unnecessary work. I’m not sure the WTF::move is needed, by the way. Having a regression test is the key.

> Source/WTF/wtf/HashSet.h:323
> +    template<typename T, typename U, typename V>
> +    inline auto HashSet<T, U, V>::operator=(HashSet&& other) -> HashSet&
> +    {
> +        HashSet temp = WTF::move(other);
> +        swap(temp);
> +        return *this;
> +    }

This should instead be:

    ...
    {
        m_impl = WTF::move(other.m_impl);
    }

The swap function does unnecessary work. I’m not sure the WTF::move is needed, by the way. Having a regression test is the key.
Comment 5 Anders Carlsson 2014-09-19 10:40:44 PDT
We should also make this windows only as well; MSVC seems buggy in this regard - the move ctor and move assignment operator should be generated automatically.
Comment 6 Darin Adler 2014-09-19 10:49:31 PDT
(In reply to comment #5)
> We should also make this windows only as well; MSVC seems buggy in this regard - the move ctor and move assignment operator should be generated automatically.

So it should be:

#if COMPILER(MSVC)

And be documented as a workaround for a compiler bug.
Comment 7 Anders Carlsson 2014-09-19 10:54:27 PDT
(In reply to comment #6)
> (In reply to comment #5)
> > We should also make this windows only as well; MSVC seems buggy in this regard - the move ctor and move assignment operator should be generated automatically.
> 
> So it should be:
> 
> #if COMPILER(MSVC)
> 
> And be documented as a workaround for a compiler bug.

Looking at http://blogs.msdn.com/b/vcblog/archive/2014/06/11/c-11-14-feature-tables-for-visual-studio-14-ctp1.aspx it's likely that it's been fixed in VS 2014, so I think we should check for VS2013 explicitly.