[webkit-reviews] review granted: [Bug 176476] Introduce a utility routine to create a Vector from another based on each individual item : [Attachment 320143] map syntax

bugzilla-daemon at webkit.org bugzilla-daemon at webkit.org
Sun Sep 10 13:24:16 PDT 2017


Darin Adler <darin at apple.com> has granted youenn fablet <youennf at gmail.com>'s
request for review:
Bug 176476: Introduce a utility routine to create a Vector from another based
on each individual item
https://bugs.webkit.org/show_bug.cgi?id=176476

Attachment 320143: map syntax

https://bugs.webkit.org/attachment.cgi?id=320143&action=review




--- Comment #14 from Darin Adler <darin at apple.com> ---
Comment on attachment 320143
  --> https://bugs.webkit.org/attachment.cgi?id=320143
map syntax

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

I don’t like the idea of having both a member function named map and a free
function named map, but with two different semantics. I am saying review+ but
we should straighten this out. I would lean towards having only the free
function, and overloading it to have a more efficient version when it’s passed
something that can be more readily inlined.

>>> Source/WTF/wtf/Vector.h:654
>>> +	 template<typename V, V (*transform)(ValueType&&)> Vector<V> map()
>> 
>> Why can't you figure out V from the return type of the transform using some
std:: magic?
> 
> 

std::result_of and std::invoke_result are supposed to solve this problem.

>>> Source/WebCore/Modules/cache/DOMCache.cpp:412
>>> +	     promise.resolve(result.releaseReturnValue().map<Ref<FetchRequest>,
copyRequest>());
>> 
>> Why wouldn't whatever "lambda" version we come up with just handle this?
Like, you could just write this as:
>> map(result.releaseReturnValue(), copyRequest)?
>> or:
>> result.releaseReturnValue().map(copyRequest)
>> depending on if we make it a free function or not
> 
> A lambda version will always work for those cases but would be slightly less
optimal.

The compiler never inlines a lambda?


More information about the webkit-reviews mailing list