Bug 149434 - The binding for getDistributedNodes unnecessarily makes a vector of nodes
Summary: The binding for getDistributedNodes unnecessarily makes a vector of nodes
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: DOM (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Ryosuke Niwa
URL:
Keywords:
Depends on:
Blocks: 148695
  Show dependency treegraph
 
Reported: 2015-09-21 16:35 PDT by Ryosuke Niwa
Modified: 2015-09-21 17:26 PDT (History)
2 users (show)

See Also:


Attachments
Fixes the bug (3.48 KB, patch)
2015-09-21 16:48 PDT, Ryosuke Niwa
darin: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
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>