Bug 224981

Summary: Refactor ValueRange from enum to enum class
Product: WebKit Reporter: Tyler Wilcock <twilco.o>
Component: CSSAssignee: Tyler Wilcock <twilco.o>
Status: RESOLVED FIXED    
Severity: Normal CC: darin, eric.carlson, esprehn+autocc, ews-watchlist, glenn, gyuyoung.kim, jer.noble, macpherson, menard, philipj, sam, sergio, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
Patch none

Description Tyler Wilcock 2021-04-23 09:08:56 PDT
ValueRange looks like this:

enum ValueRange {
    ValueRangeAll,
    ValueRangeNonNegative
}

It should be an `enum class : uint8_t`.  This would make it smaller (one byte versus four) and harder to misuse.
Comment 1 Tyler Wilcock 2021-04-23 09:19:42 PDT
Created attachment 426915 [details]
Patch
Comment 2 Tyler Wilcock 2021-04-23 17:50:57 PDT
Darin, here's one follow-up from https://bugs.webkit.org/show_bug.cgi?id=224718#c24 (parsing @counter-style descriptors).
Comment 3 EWS 2021-04-24 09:02:16 PDT
Committed r276550 (236990@main): <https://commits.webkit.org/236990@main>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 426915 [details].
Comment 4 Radar WebKit Bug Importer 2021-04-24 09:03:14 PDT
<rdar://problem/77106648>
Comment 5 Darin Adler 2021-04-24 10:11:58 PDT
Comment on attachment 426915 [details]
Patch

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

> Source/WebCore/ChangeLog:23
> +        making it smaller (one byte versus four) and harder to misuse (no
> +        auto-coercion to number types).

Seems like a great change.

For future reference, adding the underlying type of uint8_t is independent of changing from enum to enum class. Both are good ideas.

I believe that for two-value enumerations, bool is an even better underlying type than uint8_t, and on the modern compilers we are compiling with both will use a single byte for storage.