Bug 234583

Summary: Encapsulate gradient color stops into a self contained class
Product: WebKit Reporter: Sam Weinig <sam>
Component: PlatformAssignee: Sam Weinig <sam>
Status: RESOLVED FIXED    
Severity: Normal CC: annulen, changseok, darin, dino, esprehn+autocc, ews-watchlist, fmalita, glenn, gyuyoung.kim, kondapallykalyan, macpherson, menard, pdr, ryuan.choi, sabouhallawa, schenney, sergio, simon.fraser, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
Patch
ews-feeder: commit-queue-
Patch
none
Patch ews-feeder: commit-queue-

Description Sam Weinig 2021-12-21 17:54:11 PST
Rather than having the gradient color stop vector and a separate m_stopsSorted bit in Gradient, it would be slightly nicer to have a encapsulated object to represent the stops set.
Comment 1 Sam Weinig 2021-12-22 09:45:18 PST
Created attachment 447809 [details]
Patch
Comment 2 Sam Weinig 2021-12-22 09:49:26 PST
I think this is an improvement, but I would eventually like to make Gradient immutable after construction if we can, to simplify things further.

The only place that remains that uses mutation is CanvasGradient, but since mutation invalidates everything anyway, we just store both a GradientColorStops and a lazy created Gradient on CanvasGradient, and just invalidate the Gradient when ever a stop is added.

If we made Gradient immutable, we could simplify sorting and the hash cache by always sorting on creation.
Comment 3 Sam Weinig 2021-12-22 09:49:31 PST Comment hidden (obsolete)
Comment 4 Sam Weinig 2021-12-22 09:55:16 PST Comment hidden (obsolete)
Comment 5 Sam Weinig 2021-12-23 11:00:06 PST
Created attachment 447884 [details]
Patch
Comment 6 EWS 2021-12-23 13:36:14 PST
Committed r287411 (245546@main): <https://commits.webkit.org/245546@main>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 447884 [details].
Comment 7 Radar WebKit Bug Importer 2021-12-23 13:37:16 PST
<rdar://problem/86863966>
Comment 8 Darin Adler 2021-12-24 08:57:42 PST
Comment on attachment 447884 [details]
Patch

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

> Source/WebCore/platform/graphics/GradientColorStops.h:91
> +    template<typename MapFunction> GradientColorStops mapColors(MapFunction&& mapFunction) const

I suggest const MapFunction& here.
Comment 9 Sam Weinig 2021-12-25 19:53:06 PST
(In reply to Darin Adler from comment #8)
> Comment on attachment 447884 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=447884&action=review
> 
> > Source/WebCore/platform/graphics/GradientColorStops.h:91
> > +    template<typename MapFunction> GradientColorStops mapColors(MapFunction&& mapFunction) const
> 
> I suggest const MapFunction& here.

I think that would disallow stateful lambdas, which can be quite useful. What do you see as the benefit of a const reference over the universal reference here?
Comment 10 Darin Adler 2021-12-27 11:54:54 PST
(In reply to Sam Weinig from comment #9)
> (In reply to Darin Adler from comment #8)
> > I suggest const MapFunction& here.
> 
> I think that would disallow stateful lambdas, which can be quite useful.
> What do you see as the benefit of a const reference over the universal
> reference here?

I thought the const reference would make it clear that this function does not take ownership of the passed in function, thus the function can be reused elsewhere.

It didn’t occur to me that taking a const T& prevents the use of stateful lambdas or that this is a universal reference, rather than an rvalue reference. I wonder what our general design pattern should be. I was thinking about when we use an rvalue reference for WTF::Function: Function&& vs. const Function&.