Bug 149434

Summary: The binding for getDistributedNodes unnecessarily makes a vector of nodes
Product: WebKit Reporter: Ryosuke Niwa <rniwa>
Component: DOMAssignee: Ryosuke Niwa <rniwa>
Status: RESOLVED FIXED    
Severity: Normal CC: cdumez, koivisto
Priority: P2    
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
Bug Depends on:    
Bug Blocks: 148695    
Attachments:
Description Flags
Fixes the bug darin: review+

Description Ryosuke Niwa 2015-09-21 16:35:25 PDT
We shouldn't need to create a Vector<RefPtr<Node>> just so that the binding code can generate the right code.
Comment 1 Ryosuke Niwa 2015-09-21 16:48:33 PDT
Created attachment 261703 [details]
Fixes the bug
Comment 2 Darin Adler 2015-09-21 16:54:41 PDT
Comment on attachment 261703 [details]
Fixes the bug

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

> Source/WebCore/bindings/js/JSDOMBinding.h:467
> +template<typename T>
> +inline JSC::JSValue jsArray(JSC::ExecState* exec, JSDOMGlobalObject* globalObject, const Vector<T>* vector)
> +{
> +    JSC::MarkedArgumentBuffer list;
> +    if (vector) {
> +        for (auto& element : *vector)
> +            list.append(JSValueTraits<T>::arrayJSValue(exec, globalObject, element));
> +    }
> +    return JSC::constructArray(exec, nullptr, globalObject, list);
> +}

I suggest writing this instead:

    template<typename T, size_t inlineCapacity> inline JSC::JSValue jsArray(JSC::ExecState* exec, JSDOMGlobalObject* globalObject, const Vector<T, inlineCapacity>* vector)
    {
        if (!vector)
            return JSC::constructEmptyArray(exec);
        return jsArray(exec, globalObject, *vector);
    }
Comment 3 Ryosuke Niwa 2015-09-21 17:26:21 PDT
Committed r190093: <http://trac.webkit.org/changeset/190093>