RESOLVED FIXED 234583
Encapsulate gradient color stops into a self contained class
https://bugs.webkit.org/show_bug.cgi?id=234583
Summary Encapsulate gradient color stops into a self contained class
Sam Weinig
Reported 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.
Attachments
Patch (43.21 KB, patch)
2021-12-22 09:45 PST, Sam Weinig
ews-feeder: commit-queue-
Patch (43.25 KB, patch)
2021-12-22 09:55 PST, Sam Weinig
no flags
Patch (44.65 KB, patch)
2021-12-23 11:00 PST, Sam Weinig
ews-feeder: commit-queue-
Sam Weinig
Comment 1 2021-12-22 09:45:18 PST
Sam Weinig
Comment 2 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.
Sam Weinig
Comment 3 2021-12-22 09:49:31 PST Comment hidden (obsolete)
Sam Weinig
Comment 4 2021-12-22 09:55:16 PST Comment hidden (obsolete)
Sam Weinig
Comment 5 2021-12-23 11:00:06 PST
EWS
Comment 6 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].
Radar WebKit Bug Importer
Comment 7 2021-12-23 13:37:16 PST
Darin Adler
Comment 8 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.
Sam Weinig
Comment 9 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?
Darin Adler
Comment 10 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&.
Note You need to log in before you can comment on or make changes to this bug.