Bug 127274 - Move WebAudio source code to std::unique_ptr
Summary: Move WebAudio source code to std::unique_ptr
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: New Bugs (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Zan Dobersek
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-01-20 02:05 PST by Zan Dobersek
Modified: 2014-01-20 13:31 PST (History)
7 users (show)

See Also:


Attachments
Patch (91.97 KB, patch)
2014-01-20 02:07 PST, Zan Dobersek
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Zan Dobersek 2014-01-20 02:05:48 PST
Move WebAudio source code to std::unique_ptr
Comment 1 Zan Dobersek 2014-01-20 02:07:32 PST
Created attachment 221637 [details]
Patch
Comment 2 Zan Dobersek 2014-01-20 12:31:55 PST
Comment on attachment 221637 [details]
Patch

Clearing flags on attachment: 221637

Committed r162368: <http://trac.webkit.org/changeset/162368>
Comment 3 Zan Dobersek 2014-01-20 12:32:05 PST
All reviewed patches have been landed.  Closing bug.
Comment 4 Darin Adler 2014-01-20 13:26:07 PST
Comment on attachment 221637 [details]
Patch

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

> Source/WebCore/Modules/webaudio/AudioNode.cpp:334
> -    ASSERT(m_inputs.contains(input));
> -    if (!m_inputs.contains(input))
> -        return;
> +    for (const std::unique_ptr<AudioNodeInput>& savedInput : m_inputs) {
> +        if (input == savedInput.get()) {
> +            input->updateInternalBus();
> +            return;
> +        }
> +    }
>  
> -    input->updateInternalBus();
> +    ASSERT_NOT_REACHED();

The new code seems clearly worse than the old here. Is there something we can do about that? Maybe we can overload the contains function so it can be used with a raw pointer in a case like this?

> Source/WebCore/platform/audio/HRTFDatabaseLoader.cpp:80
> -    m_hrtfDatabase.clear();
> +    m_hrtfDatabase.reset();

Normally we just use

    m_hrtfDatabase = nullptr;

for a case like this.

> Source/WebCore/platform/audio/HRTFKernel.h:60
> +        return adoptRef(new HRTFKernel(std::forward<std::unique_ptr<FFTFrame>>(fftFrame), frameDelay, sampleRate));

I’m really surprised that we needed the template argument for std::forward here. I would expect just std::forward(fftFrame) or std::move(fftFrame) would work.
Comment 5 Anders Carlsson 2014-01-20 13:31:37 PST
(In reply to comment #4)
> The new code seems clearly worse than the old here. Is there something we can do about that? Maybe we can overload the contains function so it can be used with a raw pointer in a case like this?

I'd actually like to get rid of Vector::contains since it's O(n). Forcing users to write out the full loop makes it more obvious that it's a linear operation.

> 
> > Source/WebCore/platform/audio/HRTFDatabaseLoader.cpp:80
> > -    m_hrtfDatabase.clear();
> > +    m_hrtfDatabase.reset();
> 
> Normally we just use
> 
>     m_hrtfDatabase = nullptr;
> 
> for a case like this.
> 
> > Source/WebCore/platform/audio/HRTFKernel.h:60
> > +        return adoptRef(new HRTFKernel(std::forward<std::unique_ptr<FFTFrame>>(fftFrame), frameDelay, sampleRate));
> 
> I’m really surprised that we needed the template argument for std::forward here. I would expect just std::forward(fftFrame) or std::move(fftFrame) would work.

std::forward should only be used together with template type parameters. This should use move.