RESOLVED FIXED 238977
Finish porting code base to String::fromLatin1() and make String(const char*) private
https://bugs.webkit.org/show_bug.cgi?id=238977
Summary Finish porting code base to String::fromLatin1() and make String(const char*)...
Chris Dumez
Reported 2022-04-07 20:06:14 PDT
Finish porting code base to String::fromLatin1() and make String(const char*) private.
Attachments
WIP Patch (82.65 KB, patch)
2022-04-07 20:49 PDT, Chris Dumez
ews-feeder: commit-queue-
WIP Patch (83.24 KB, patch)
2022-04-07 21:00 PDT, Chris Dumez
ews-feeder: commit-queue-
WIP Patch (83.73 KB, patch)
2022-04-07 21:04 PDT, Chris Dumez
ews-feeder: commit-queue-
WIP Patch (86.55 KB, patch)
2022-04-07 21:17 PDT, Chris Dumez
ews-feeder: commit-queue-
WIP Patch (103.88 KB, patch)
2022-04-07 21:43 PDT, Chris Dumez
ews-feeder: commit-queue-
WIP Patch (104.89 KB, patch)
2022-04-07 22:01 PDT, Chris Dumez
ews-feeder: commit-queue-
WIP Patch (105.55 KB, patch)
2022-04-07 22:08 PDT, Chris Dumez
ews-feeder: commit-queue-
WIP Patch (106.24 KB, patch)
2022-04-07 22:13 PDT, Chris Dumez
ews-feeder: commit-queue-
WIP Patch (115.44 KB, patch)
2022-04-07 22:31 PDT, Chris Dumez
no flags
Patch (133.73 KB, patch)
2022-04-07 22:45 PDT, Chris Dumez
ews-feeder: commit-queue-
Patch (136.14 KB, patch)
2022-04-07 22:49 PDT, Chris Dumez
no flags
Patch (147.15 KB, patch)
2022-04-08 07:20 PDT, Chris Dumez
ews-feeder: commit-queue-
Patch (149.12 KB, patch)
2022-04-08 07:39 PDT, Chris Dumez
no flags
Patch (149.73 KB, patch)
2022-04-08 08:00 PDT, Chris Dumez
no flags
Patch (150.65 KB, patch)
2022-04-08 08:16 PDT, Chris Dumez
ews-feeder: commit-queue-
Patch (152.64 KB, patch)
2022-04-08 08:39 PDT, Chris Dumez
no flags
Patch (153.60 KB, patch)
2022-04-08 08:57 PDT, Chris Dumez
ews-feeder: commit-queue-
Patch (155.38 KB, patch)
2022-04-08 09:35 PDT, Chris Dumez
no flags
Patch (156.22 KB, patch)
2022-04-08 09:48 PDT, Chris Dumez
ews-feeder: commit-queue-
Patch (157.79 KB, patch)
2022-04-08 09:57 PDT, Chris Dumez
no flags
Patch (157.82 KB, patch)
2022-04-08 10:02 PDT, Chris Dumez
ews-feeder: commit-queue-
Patch (158.57 KB, patch)
2022-04-08 10:07 PDT, Chris Dumez
ews-feeder: commit-queue-
Patch (160.38 KB, patch)
2022-04-08 10:51 PDT, Chris Dumez
no flags
Patch (162.89 KB, patch)
2022-04-08 11:02 PDT, Chris Dumez
ews-feeder: commit-queue-
Patch (163.64 KB, patch)
2022-04-08 12:42 PDT, Chris Dumez
ews-feeder: commit-queue-
Patch (164.36 KB, patch)
2022-04-08 14:30 PDT, Chris Dumez
no flags
Patch (166.71 KB, patch)
2022-04-08 16:51 PDT, Chris Dumez
ews-feeder: commit-queue-
Patch (170.71 KB, patch)
2022-04-08 18:04 PDT, Chris Dumez
ews-feeder: commit-queue-
Patch (172.14 KB, patch)
2022-04-08 19:22 PDT, Chris Dumez
ews-feeder: commit-queue-
Patch (178.05 KB, patch)
2022-04-08 20:06 PDT, Chris Dumez
no flags
Patch (183.92 KB, patch)
2022-04-08 20:45 PDT, Chris Dumez
ews-feeder: commit-queue-
Patch (184.48 KB, patch)
2022-04-08 21:51 PDT, Chris Dumez
no flags
Patch (185.50 KB, patch)
2022-04-08 22:17 PDT, Chris Dumez
no flags
Patch (186.14 KB, patch)
2022-04-08 22:40 PDT, Chris Dumez
no flags
Patch (186.72 KB, patch)
2022-04-08 22:56 PDT, Chris Dumez
no flags
Patch (187.49 KB, patch)
2022-04-08 23:04 PDT, Chris Dumez
no flags
Patch (202.24 KB, patch)
2022-04-08 23:16 PDT, Chris Dumez
no flags
Patch (203.39 KB, patch)
2022-04-08 23:26 PDT, Chris Dumez
ews-feeder: commit-queue-
Patch (204.04 KB, patch)
2022-04-08 23:32 PDT, Chris Dumez
no flags
Patch (208.99 KB, patch)
2022-04-09 09:42 PDT, Chris Dumez
ews-feeder: commit-queue-
Patch (209.61 KB, patch)
2022-04-09 10:40 PDT, Chris Dumez
ews-feeder: commit-queue-
Patch (214.61 KB, patch)
2022-04-09 11:41 PDT, Chris Dumez
no flags
Patch (216.31 KB, patch)
2022-04-09 14:22 PDT, Chris Dumez
ews-feeder: commit-queue-
Patch (217.67 KB, patch)
2022-04-09 15:33 PDT, Chris Dumez
no flags
Patch (217.67 KB, patch)
2022-04-09 18:13 PDT, Chris Dumez
ews-feeder: commit-queue-
Patch (218.70 KB, patch)
2022-04-09 20:05 PDT, Chris Dumez
no flags
Patch (219.63 KB, patch)
2022-04-09 22:34 PDT, Chris Dumez
no flags
Patch (220.30 KB, patch)
2022-04-10 13:01 PDT, Chris Dumez
no flags
Patch (221.51 KB, patch)
2022-04-10 16:26 PDT, Chris Dumez
ews-feeder: commit-queue-
Chris Dumez
Comment 1 2022-04-07 20:49:55 PDT
Created attachment 457008 [details] WIP Patch
Chris Dumez
Comment 2 2022-04-07 21:00:37 PDT
Created attachment 457009 [details] WIP Patch
Chris Dumez
Comment 3 2022-04-07 21:04:12 PDT
Created attachment 457010 [details] WIP Patch
Chris Dumez
Comment 4 2022-04-07 21:17:55 PDT
Created attachment 457014 [details] WIP Patch
Chris Dumez
Comment 5 2022-04-07 21:43:04 PDT
Created attachment 457015 [details] WIP Patch
Chris Dumez
Comment 6 2022-04-07 22:01:47 PDT
Created attachment 457017 [details] WIP Patch
Chris Dumez
Comment 7 2022-04-07 22:08:16 PDT
Created attachment 457018 [details] WIP Patch
Chris Dumez
Comment 8 2022-04-07 22:13:16 PDT
Created attachment 457019 [details] WIP Patch
Chris Dumez
Comment 9 2022-04-07 22:31:23 PDT
Created attachment 457021 [details] WIP Patch
Chris Dumez
Comment 10 2022-04-07 22:45:31 PDT
Chris Dumez
Comment 11 2022-04-07 22:49:58 PDT
Chris Dumez
Comment 12 2022-04-08 07:20:35 PDT
Chris Dumez
Comment 13 2022-04-08 07:39:57 PDT
Chris Dumez
Comment 14 2022-04-08 08:00:11 PDT
Chris Dumez
Comment 15 2022-04-08 08:16:33 PDT
Chris Dumez
Comment 16 2022-04-08 08:39:08 PDT
Chris Dumez
Comment 17 2022-04-08 08:57:09 PDT
Chris Dumez
Comment 18 2022-04-08 09:35:33 PDT
Chris Dumez
Comment 19 2022-04-08 09:48:53 PDT
Chris Dumez
Comment 20 2022-04-08 09:57:09 PDT
Chris Dumez
Comment 21 2022-04-08 10:02:27 PDT
Chris Dumez
Comment 22 2022-04-08 10:07:55 PDT
Chris Dumez
Comment 23 2022-04-08 10:51:46 PDT
Chris Dumez
Comment 24 2022-04-08 11:02:15 PDT
Chris Dumez
Comment 25 2022-04-08 12:42:11 PDT
Chris Dumez
Comment 26 2022-04-08 14:30:47 PDT
Chris Dumez
Comment 27 2022-04-08 16:51:36 PDT
Chris Dumez
Comment 28 2022-04-08 18:04:53 PDT
Chris Dumez
Comment 29 2022-04-08 19:22:15 PDT
Chris Dumez
Comment 30 2022-04-08 20:06:10 PDT
Chris Dumez
Comment 31 2022-04-08 20:45:14 PDT
Chris Dumez
Comment 32 2022-04-08 21:51:59 PDT
Chris Dumez
Comment 33 2022-04-08 22:17:41 PDT
Chris Dumez
Comment 34 2022-04-08 22:40:16 PDT
Chris Dumez
Comment 35 2022-04-08 22:56:45 PDT
Chris Dumez
Comment 36 2022-04-08 23:04:01 PDT
Chris Dumez
Comment 37 2022-04-08 23:16:28 PDT
Chris Dumez
Comment 38 2022-04-08 23:26:50 PDT
Chris Dumez
Comment 39 2022-04-08 23:32:40 PDT
Chris Dumez
Comment 40 2022-04-09 09:42:33 PDT
Chris Dumez
Comment 41 2022-04-09 10:40:55 PDT
Chris Dumez
Comment 42 2022-04-09 11:41:23 PDT
Chris Dumez
Comment 43 2022-04-09 14:22:07 PDT
Chris Dumez
Comment 44 2022-04-09 15:33:01 PDT
Chris Dumez
Comment 45 2022-04-09 18:13:32 PDT
Chris Dumez
Comment 46 2022-04-09 20:05:10 PDT
Chris Dumez
Comment 47 2022-04-09 22:34:53 PDT
Chris Dumez
Comment 48 2022-04-10 13:01:23 PDT
Darin Adler
Comment 49 2022-04-10 15:37:28 PDT
Comment on attachment 457209 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=457209&action=review > Source/WTF/wtf/text/ASCIILiteral.h:73 > + return !a; This should be: return false; I don’t like checking !a again, when the line just above has already checked it. Or write this: if (!a || !b) return a == b; I kind of like that one. > Source/WTF/wtf/text/ASCIILiteral.h:83 > + if (!a) > + return !b; > + if (!b) > + return !a; > return !strcmp(a.characters(), b.characters()); Same applies here. Or we could take advantage of the function above and just write: return a == b.characters(); > Source/WTF/wtf/text/WTFString.h:81 > WTF_EXPORT_PRIVATE String(const LChar* characters, unsigned length); > WTF_EXPORT_PRIVATE String(const char* characters, unsigned length); I think that later these should be named String::fromLatin1 too. > Source/WTF/wtf/text/WTFString.h:82 > ALWAYS_INLINE static String fromLatin1(const char* characters) { return String { characters }; } I still like the idea of adding a fromASCII, but I am not pushing you to do that at this time. > Source/WebCore/Modules/mediastream/gstreamer/GStreamerDataChannelHandler.cpp:88 > + init.protocol = String::fromUTF8(protocol.get()); Using fromUTF8 adds in the possibility of failure and the need to check for null, perhaps. Maybe some day we will want to rename fromUTF8 to have the word "try" in its name. > Source/WebCore/Modules/mediastream/gstreamer/GStreamerWebRTCUtils.cpp:159 > + parameters.rid = String::fromUTF8(gst_structure_get_string(rtcParameters, "rid")); Ditto, this now has a new possible failure. > Source/WebCore/html/canvas/WebGLRenderingContextBase.cpp:1908 > - String str = "WebGL: checkFramebufferStatus:" + String(reason); > + String str = makeString("WebGL: checkFramebufferStatus: ", reason); > printToConsole(MessageLevel::Warning, str); We should not bother with the local variable here. > Source/WebCore/loader/soup/ResourceLoaderSoup.cpp:68 > + auto contentTypeString = String::fromLatin1(contentType.get()); > ResourceResponse response { url, extractMIMETypeFromMediaType(contentTypeString), static_cast<long long>(dataSize), extractCharsetFromMediaType(contentTypeString).toString() }; Doesn’t extractMIMETypeFromMediaType take a StringView? > Source/WebCore/platform/graphics/GLContext.cpp:179 > + auto versionString = String::fromLatin1(reinterpret_cast<const char*>(::glGetString(GL_VERSION))); This should be changed to use StringView some day. No reason to allocate all these strings just to parse/split something. > Source/WebCore/platform/graphics/gstreamer/GStreamerRegistryScanner.cpp:179 > + auto metadata = String::fromLatin1(gst_element_factory_get_metadata(factory, GST_ELEMENT_METADATA_KLASS)); This should be changed to use StringView some day. No reason to allocate a string just to parse/split something. > Source/WebDriver/WebDriverService.cpp:569 > + completionHandler(CommandResult::fail(CommandResult::ErrorCode::InvalidSessionID, String("session deleted because of page crash or hang."_s))); I bet most of these String() in this file aren’t needed. > Tools/DumpRenderTree/win/DumpRenderTree.cpp:1177 > // DumpRenderTree does not support checking for abandonded documents. Spelling error in abandoned here. > Tools/DumpRenderTree/win/DumpRenderTree.cpp:1178 > + CString result("\n"); So strange to use any string at all for this code. Could just have this instead: fputs("Content-Type: text/plain\nContent-Length: 1\n\n#EOF\n", stdout); fputs("#EOF\n", stderr); fflush(stdout); fflush(stderr); But really not sure if we want to improve this. > Tools/TestWebKitAPI/Tests/WebCore/PublicSuffix.cpp:182 > + EXPECT_EQ(String::fromLatin1("åäö"), topPrivatelyControlledDomain("åäö"_s)); > + EXPECT_EQ(String::fromLatin1("ÅÄÖ"), topPrivatelyControlledDomain("ÅÄÖ"_s)); This already was not OK. We should not have any non-ASCII characters in an ASCIILiteral. In fact, we should be checking that at compile time. If we did, this would fail to compile. > Tools/TestWebKitAPI/Tests/WebKitCocoa/EventAttribution.mm:285 > + auto key = signingParty == TokenSigningParty::Source ? String("source_unlinkable_token"_s) : String("destination_unlinkable_token"_s); Should be able to take all the String() out here. > Tools/TestWebKitAPI/Tests/WebKitCocoa/EventAttribution.mm:323 > + auto key = signingParty == TokenSigningParty::Source ? String("source_secret_token"_s) : String("destination_secret_token"_s); And here. > Tools/TestWebKitAPI/Tests/WebKitCocoa/EventAttribution.mm:331 > + key = signingParty == TokenSigningParty::Source ? String("source_secret_token_signature"_s) : String("destination_secret_token_signature"_s); And here. > Tools/TestWebKitAPI/Tests/mac/ContextMenuCanCopyURL.mm:104 > + EXPECT_EQ(String("http://www.webkit.org/"_s), String([url absoluteString])); Don’t need a String() around the ASCIILiteral, I don’t think. > Tools/TestWebKitAPI/Tests/mac/WebViewCanPasteURL.mm:49 > + EXPECT_EQ(String("http://www.webkit.org/"_s), String(text)); Ditto. > Tools/TestWebKitAPI/Tests/mac/WillPerformClientRedirectToURLCrash.mm:67 > + EXPECT_EQ(String("PASS"_s), String(message)); Ditto.
Chris Dumez
Comment 50 2022-04-10 16:02:02 PDT
Comment on attachment 457209 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=457209&action=review >> Source/WTF/wtf/text/ASCIILiteral.h:73 >> + return !a; > > This should be: > > return false; > > I don’t like checking !a again, when the line just above has already checked it. Or write this: > > if (!a || !b) > return a == b; > > I kind of like that one. Ok, will change. I think I'll have to use this though: if (!a || !b) return a.characters() == b; FYI, I had copied the logic from String's operator==. >> Source/WTF/wtf/text/WTFString.h:81 >> WTF_EXPORT_PRIVATE String(const char* characters, unsigned length); > > I think that later these should be named String::fromLatin1 too. I agree. >> Source/WTF/wtf/text/WTFString.h:82 >> ALWAYS_INLINE static String fromLatin1(const char* characters) { return String { characters }; } > > I still like the idea of adding a fromASCII, but I am not pushing you to do that at this time. I don't fully understand the benefit of the fromASCII(). Sure, we can artificially enforce via assertions that the input is ASCII but it won't really help us write a more efficient constructor, will it? If so, is it really worth adding yet another way to construct a String? >> Source/WebCore/loader/soup/ResourceLoaderSoup.cpp:68 >> ResourceResponse response { url, extractMIMETypeFromMediaType(contentTypeString), static_cast<long long>(dataSize), extractCharsetFromMediaType(contentTypeString).toString() }; > > Doesn’t extractMIMETypeFromMediaType take a StringView? No, not at the moment. It could but it seems there is a potential optimization where it returned the String passed in, as-is. >> Tools/TestWebKitAPI/Tests/WebCore/PublicSuffix.cpp:182 >> + EXPECT_EQ(String::fromLatin1("ÅÄÖ"), topPrivatelyControlledDomain("ÅÄÖ"_s)); > > This already was not OK. We should not have any non-ASCII characters in an ASCIILiteral. In fact, we should be checking that at compile time. If we did, this would fail to compile. Weird, we do have assertions in place already: ``` constexpr ASCIILiteral operator"" _s(const char* characters, size_t n) { #if ASSERT_ENABLED for (size_t i = 0; i < n; ++i) ASSERT_UNDER_CONSTEXPR_CONTEXT(isASCII(characters[i])); #else UNUSED_PARAM(n); #endif return ASCIILiteral::fromLiteralUnsafe(characters); } ```
Chris Dumez
Comment 51 2022-04-10 16:19:10 PDT
(In reply to Chris Dumez from comment #50) > Comment on attachment 457209 [details] > Patch > > View in context: > https://bugs.webkit.org/attachment.cgi?id=457209&action=review > > >> Source/WTF/wtf/text/ASCIILiteral.h:73 > >> + return !a; > > > > This should be: > > > > return false; > > > > I don’t like checking !a again, when the line just above has already checked it. Or write this: > > > > if (!a || !b) > > return a == b; > > > > I kind of like that one. > > Ok, will change. I think I'll have to use this though: > if (!a || !b) > return a.characters() == b; > > FYI, I had copied the logic from String's operator==. > > >> Source/WTF/wtf/text/WTFString.h:81 > >> WTF_EXPORT_PRIVATE String(const char* characters, unsigned length); > > > > I think that later these should be named String::fromLatin1 too. > > I agree. > > >> Source/WTF/wtf/text/WTFString.h:82 > >> ALWAYS_INLINE static String fromLatin1(const char* characters) { return String { characters }; } > > > > I still like the idea of adding a fromASCII, but I am not pushing you to do that at this time. > > I don't fully understand the benefit of the fromASCII(). Sure, we can > artificially enforce via assertions that the input is ASCII but it won't > really help us write a more efficient constructor, will it? > If so, is it really worth adding yet another way to construct a String? > > >> Source/WebCore/loader/soup/ResourceLoaderSoup.cpp:68 > >> ResourceResponse response { url, extractMIMETypeFromMediaType(contentTypeString), static_cast<long long>(dataSize), extractCharsetFromMediaType(contentTypeString).toString() }; > > > > Doesn’t extractMIMETypeFromMediaType take a StringView? > > No, not at the moment. It could but it seems there is a potential > optimization where it returned the String passed in, as-is. > > >> Tools/TestWebKitAPI/Tests/WebCore/PublicSuffix.cpp:182 > >> + EXPECT_EQ(String::fromLatin1("ÅÄÖ"), topPrivatelyControlledDomain("ÅÄÖ"_s)); > > > > This already was not OK. We should not have any non-ASCII characters in an ASCIILiteral. In fact, we should be checking that at compile time. If we did, this would fail to compile. > > Weird, we do have assertions in place already: > ``` > constexpr ASCIILiteral operator"" _s(const char* characters, size_t n) > { > #if ASSERT_ENABLED > for (size_t i = 0; i < n; ++i) > ASSERT_UNDER_CONSTEXPR_CONTEXT(isASCII(characters[i])); > #else > UNUSED_PARAM(n); > #endif > return ASCIILiteral::fromLiteralUnsafe(characters); > } > ``` Oh, the assertion does hit: ASSERTION FAILED: isASCII(characters[i]) /Volumes/Data/WebKit/OpenSource/WebKitBuild/Debug/usr/local/include/wtf/text/ASCIILiteral.h(88) : WTF::ASCIILiteral WTF::StringLiterals::operator""_s(const char *, size_t) worker/0 TestWebKitAPI.PublicSuffix.TopPrivatelyControlledDomain Crashed Ran 1 tests of 1 with 0 successful ------------------------------ Test suite failed Crashed TestWebKitAPI.PublicSuffix.TopPrivatelyControlledDomain ASSERTION FAILED: isASCII(characters[i]) /Volumes/Data/WebKit/OpenSource/WebKitBuild/Debug/usr/local/include/wtf/text/ASCIILiteral.h(88) : WTF::ASCIILiteral WTF::StringLiterals::operator""_s(const char *, size_t)
Chris Dumez
Comment 52 2022-04-10 16:26:32 PDT
Chris Dumez
Comment 53 2022-04-10 21:40:22 PDT
Comment on attachment 457216 [details] Patch Clearing flags on attachment: 457216 Committed r292696 (?): <https://commits.webkit.org/r292696>
Chris Dumez
Comment 54 2022-04-10 21:40:25 PDT
All reviewed patches have been landed. Closing bug.
Radar WebKit Bug Importer
Comment 55 2022-04-10 21:47:57 PDT
EWS
Comment 56 2022-04-10 22:32:28 PDT
Found 2 new test failures: fast/multicol/client-rects-spanners.html, fast/multicol/span/span-as-immediate-child-generated-content.html
Darin Adler
Comment 57 2022-04-11 08:42:21 PDT
Comment on attachment 457209 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=457209&action=review >>> Source/WTF/wtf/text/WTFString.h:82 >>> ALWAYS_INLINE static String fromLatin1(const char* characters) { return String { characters }; } >> >> I still like the idea of adding a fromASCII, but I am not pushing you to do that at this time. > > I don't fully understand the benefit of the fromASCII(). Sure, we can artificially enforce via assertions that the input is ASCII but it won't really help us write a more efficient constructor, will it? > If so, is it really worth adding yet another way to construct a String? Not critical. Maybe we should discuss this in person at some point. I still like the idea and I think it is valuable for two reasons, but I don’t want to write more paragraphs about why. The two reasons are: (1) being explicit about what we intend at each call site, instead of writing fromLatin1 because it "just doesn’t matter it’s always ASCII", and (2) future-proofing these call sites a little if we want to do experiments with storing UTF-8.
Note You need to log in before you can comment on or make changes to this bug.