Bug 235461 - Improve FourCC to use more inlining, fix incorrect mix of WEBCORE_EXPORT on entire class with inline functions
Summary: Improve FourCC to use more inlining, fix incorrect mix of WEBCORE_EXPORT on e...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebCore Misc. (show other bugs)
Version: WebKit Nightly Build
Hardware: All All
: P2 Normal
Assignee: Darin Adler
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2022-01-21 16:16 PST by Darin Adler
Modified: 2022-01-23 17:00 PST (History)
5 users (show)

See Also:


Attachments
Patch (26.98 KB, patch)
2022-01-21 16:49 PST, Darin Adler
no flags Details | Formatted Diff | Diff
Patch (32.26 KB, patch)
2022-01-22 16:21 PST, Darin Adler
no flags Details | Formatted Diff | Diff
Patch (32.19 KB, patch)
2022-01-23 11:21 PST, Darin Adler
sam: review+
Details | Formatted Diff | Diff
Patch for landing (32.60 KB, patch)
2022-01-23 16:40 PST, Darin Adler
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Darin Adler 2022-01-21 16:16:23 PST
Improve FourCC to use more inlining, fix incorrect mix of WEBCORE_EXPORT on entire class with inline functions
Comment 1 Darin Adler 2022-01-21 16:49:58 PST Comment hidden (obsolete)
Comment 2 Darin Adler 2022-01-22 16:21:52 PST Comment hidden (obsolete)
Comment 3 Darin Adler 2022-01-23 11:21:13 PST
Created attachment 449758 [details]
Patch
Comment 4 Darin Adler 2022-01-23 12:04:44 PST
OK, after two false starts, this one is working and ready for review.

For FourCC itself, this makes the code easier to read, more elegant, reduces reliance on reinterpret_cast and assumptions that all platforms are little-endian, and even makes it a bit more efficient, although mostly in places where efficiency isn’t critical.

On the other hand, for the ISOBox classes, while this fixes the problem where the coding style checker says "never use inline functions in a class marked WEBCORE_EXPORT", it makes the code less elegant. The underlying cause is that because these seemingly-simple structures are instead a class hierarchy that descends from a polymorphic class with a virtual destructor. That pattern isn’t working all that well to keep the code simple, and at some point it might be worth exploring whether it’s really needed, and considering alternatives.
Comment 5 Darin Adler 2022-01-23 12:07:47 PST
Comment on attachment 449758 [details]
Patch

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

> Source/WebCore/platform/graphics/FourCC.h:34
> +    constexpr FourCC(uint32_t value) : value { value } { }

Would like to remove this so people don’t accidentally use it in cross-platform code instead of string literals, but sadly it’s too valuable for interoperating with Cocoa API that uses unsigned 32-bit ints for this, the type FourCharCode and such, so I was unable to delete it at this time.

> Source/WebCore/platform/graphics/FourCC.h:48
> +    value = data[0] << 24 | data[1] << 16 | data[2] << 8 | data[3];

Should use member construction syntax for this instead of assignment.
Comment 6 Darin Adler 2022-01-23 12:39:08 PST
Comment on attachment 449758 [details]
Patch

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

> Source/WebCore/platform/graphics/FourCC.cpp:44
> +std::array<char, 5> FourCC::string() const

We could make this inline and put it in the header. Also could make it constexpr.
Comment 7 Sam Weinig 2022-01-23 16:08:39 PST
Comment on attachment 449758 [details]
Patch

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

> Source/WebCore/platform/graphics/FourCC.cpp:36
> +        static_cast<char>(string[0]),

Are there any other rules worth asserting here? For instance, can a character be '\0'?
Comment 8 Darin Adler 2022-01-23 16:38:31 PST
Comment on attachment 449758 [details]
Patch

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

>> Source/WebCore/platform/graphics/FourCC.cpp:36
>> +        static_cast<char>(string[0]),
> 
> Are there any other rules worth asserting here? For instance, can a character be '\0'?

In practice, I think these all need to be printables, in the range 0x20-0x7F. But not sure if it’s valuable in practice to check that, though. Making a FourCC successfully with values < 0x20 for some of the characters would not have any ill effect that I am aware of. Mainly the reason this function checks that the string is all ASCII is we don’t want to chop non-8-bit UTF-16 code units and use just the low 8 bits. I think I won’t add more checks.

Related: The '\0' below is just there so we can reuse the constructor that is mainly present for ASCII literals, and it will be collapsed away by inlining.
Comment 9 Darin Adler 2022-01-23 16:40:18 PST
Created attachment 449771 [details]
Patch for landing
Comment 10 Darin Adler 2022-01-23 16:55:43 PST
Committed r288426 (246317@trunk): <https://commits.webkit.org/246317@trunk>
Comment 11 Radar WebKit Bug Importer 2022-01-23 17:00:44 PST
<rdar://problem/87947650>