Bug 205759 - Further simplify StringBuilder usage by standardizing hex formating to a single hex() function
Summary: Further simplify StringBuilder usage by standardizing hex formating to a sing...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: New Bugs (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Sam Weinig
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2020-01-03 16:28 PST by Sam Weinig
Modified: 2020-01-05 16:22 PST (History)
37 users (show)

See Also:


Attachments
Patch (25.27 KB, patch)
2020-01-03 16:38 PST, Sam Weinig
no flags Details | Formatted Diff | Diff
Patch (26.43 KB, patch)
2020-01-04 14:52 PST, Sam Weinig
no flags Details | Formatted Diff | Diff
Patch (32.41 KB, patch)
2020-01-04 15:38 PST, Sam Weinig
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Sam Weinig 2020-01-03 16:28:20 PST
Further simplify StringBuilder usage by standardizing hex formating to a single hex() function
Comment 1 Sam Weinig 2020-01-03 16:38:51 PST
Created attachment 386729 [details]
Patch
Comment 2 Sam Weinig 2020-01-03 16:43:10 PST
Darin, you have been working in this area a bit, any thoughts on this simplification? It applies the mapping:

appendByteAsHex(value, builder, case) 
  -> builder.append(hex(static_cast<unsigned char>(value), 2, case))
appendUnsignedAsHex(value, builder, case) 
  -> builder.append(hex(value, case))
appendUnsignedAsHexFixedSize(value, builder, size, case)
  -> builder.append(hex(value, size, case))
Comment 3 Darin Adler 2020-01-03 18:10:03 PST
(In reply to Sam Weinig from comment #2)
> appendByteAsHex(value, builder, case) 
>   -> builder.append(hex(static_cast<unsigned char>(value), 2, case))

This seems a bit clumsy. But I suppose only a bit.

> appendUnsignedAsHex(value, builder, case) 
>   -> builder.append(hex(value, case))
> appendUnsignedAsHexFixedSize(value, builder, size, case)
>   -> builder.append(hex(value, size, case))

These seem great to me. However, I don’t think we are being consistent in style. Sometimes we name these things:

    FormattedNumber::fixedWidth

Other times we name something similar:

    hex

We should decide what style we are after.
Comment 4 Sam Weinig 2020-01-04 12:21:22 PST
(In reply to Darin Adler from comment #3)
> (In reply to Sam Weinig from comment #2)
> > appendByteAsHex(value, builder, case) 
> >   -> builder.append(hex(static_cast<unsigned char>(value), 2, case))
> 
> This seems a bit clumsy. But I suppose only a bit.
> 
> > appendUnsignedAsHex(value, builder, case) 
> >   -> builder.append(hex(value, case))
> > appendUnsignedAsHexFixedSize(value, builder, size, case)
> >   -> builder.append(hex(value, size, case))
> 
> These seem great to me. However, I don’t think we are being consistent in
> style. Sometimes we name these things:
> 
>     FormattedNumber::fixedWidth
> 
> Other times we name something similar:
> 
>     hex
> 
> We should decide what style we are after.

We definitely need to decide on the style. I am leaning toward the shorter, unqualified names (hex(...), pad(...), fixedWidth(...), fixedPrecision(...), etc), and putting them all in a shared header for easier discovery. I could be convinced having some qualifier namespace might be helpful, e.g. all in a Format namespace (Format::hex(...), Format::pad(...), etc).

Do you have a particular preference?
Comment 5 Sam Weinig 2020-01-04 14:52:30 PST
Created attachment 386768 [details]
Patch
Comment 6 Sam Weinig 2020-01-04 14:53:03 PST
I will unify the style with fixedWidth/fixedPrecision in a follow up.
Comment 7 Sam Weinig 2020-01-04 15:38:24 PST
Created attachment 386771 [details]
Patch
Comment 8 Darin Adler 2020-01-04 20:08:05 PST
I like the short names for clarity at the point of use. I like the long names for searching the entire source tree to see where things are used.
Comment 9 Dean Jackson 2020-01-05 14:33:20 PST
Comment on attachment 386771 [details]
Patch

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

> Tools/TestWebKitAPI/Tests/WTF/HexNumber.cpp:34
> +// Not using builder.toString() or builder.toStringPreserveCapacity() because they all
> +// change internal state of builder.

Why does that matter? You never use the builder again after the expect() method.
Comment 10 Sam Weinig 2020-01-05 15:22:35 PST
(In reply to Dean Jackson from comment #9)
> Comment on attachment 386771 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=386771&action=review
> 
> > Tools/TestWebKitAPI/Tests/WTF/HexNumber.cpp:34
> > +// Not using builder.toString() or builder.toStringPreserveCapacity() because they all
> > +// change internal state of builder.
> 
> Why does that matter? You never use the builder again after the expect()
> method.

Oh, that comment was copied from another test. That was silly of me.
Comment 11 WebKit Commit Bot 2020-01-05 16:20:10 PST
The commit-queue encountered the following flaky tests while processing attachment 386771 [details]:

transitions/default-timing-function.html bug 138901 (authors: dino@apple.com and graouts@apple.com)
The commit-queue is continuing to process your patch.
Comment 12 WebKit Commit Bot 2020-01-05 16:21:05 PST
Comment on attachment 386771 [details]
Patch

Clearing flags on attachment: 386771

Committed r254046: <https://trac.webkit.org/changeset/254046>
Comment 13 WebKit Commit Bot 2020-01-05 16:21:07 PST
All reviewed patches have been landed.  Closing bug.
Comment 14 Radar WebKit Bug Importer 2020-01-05 16:22:18 PST
<rdar://problem/58328979>