Bug 225878 - Replace non-ownership transfer requiring uses of WTF::Function to use WTF::ScopeLambda to avoid allocation of WTF::Function
Summary: Replace non-ownership transfer requiring uses of WTF::Function to use WTF::Sc...
Status: NEW
Alias: None
Product: WebKit
Classification: Unclassified
Component: Web Template Framework (show other bugs)
Version: Other
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Nobody
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2021-05-17 10:28 PDT by Sam Weinig
Modified: 2021-05-24 10:29 PDT (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Sam Weinig 2021-05-17 10:28:13 PDT
Using WTF::Function (or std::function) in cases where are using a functor as an abstraction to allow scope customization, iteration or predicate functions is wasteful. We should instead be using the non-allocating WTF::ScopedLambda. 

Some examples in WebCore are:
- the traverseSubresources() functions on various classes.
- readURLsFromPasteboardAsString() in DataTransfer.cpp
- Document::forEachMediaElement()
- etc.
Comment 1 Darin Adler 2021-05-17 23:34:09 PDT
Grep for "const Function&" perhaps to find a lot of these?
Comment 2 Darin Adler 2021-05-17 23:34:31 PDT
Is there a reason this class needs to be named "lambda" and not "function"?
Comment 3 Sam Weinig 2021-05-18 16:23:09 PDT
(In reply to Darin Adler from comment #2)
> Is there a reason this class needs to be named "lambda" and not "function"?

The patch that added it doesn't give much justification: https://trac.webkit.org/changeset/191705/webkit

Phil, any reason you chose "lambda" over "function" here?
Comment 4 Radar WebKit Bug Importer 2021-05-24 10:29:20 PDT
<rdar://problem/78407384>