Bug 239306

Summary: Replace calls to substring(0, x) with the more concise left(x)
Product: WebKit Reporter: Chris Dumez <cdumez>
Component: WebCore Misc.Assignee: Chris Dumez <cdumez>
Status: RESOLVED FIXED    
Severity: Normal CC: darin, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
Bug Depends on:    
Bug Blocks: 239289    
Attachments:
Description Flags
Patch
ews-feeder: commit-queue-
Patch
none
Patch
ews-feeder: commit-queue-
Patch none

Description Chris Dumez 2022-04-13 15:27:45 PDT
Replace calls to substring(0, x) with the more concise left(x).
Comment 1 Chris Dumez 2022-04-13 16:14:47 PDT
Created attachment 457572 [details]
Patch
Comment 2 Chris Dumez 2022-04-13 17:14:53 PDT
Created attachment 457578 [details]
Patch
Comment 3 Darin Adler 2022-04-13 18:22:06 PDT
Comment on attachment 457578 [details]
Patch

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

> Source/WebCore/platform/network/MIMEHeader.cpp:75
> +        key = StringView(line).left(semiColonIndex).convertToASCIILowercase().stripWhiteSpace();

Seems *so* unlikely this (and the code above) really wants stripWhiteSpace. Almost certainly wants to strip based on some other definitions of spaces rather than "all Unicode whitespace". Should be MIME whitespace definition, which is probably like the HTML or HTTP whitespace definition.

Almost every call to stripWhiteSpace is a mistake.

Also cute that this capitalizes semicolon as if it was two words, or hyphenated.

> Source/WebCore/svg/SVGURIReference.cpp:72
>      URL kurl(base, fragmentIdentifier);

Ah, yes, "kurl".

> Source/WebCore/workers/service/server/SWServer.cpp:1271
> +    if (!scheme.startsWithIgnoringASCIICase("http"))

Nice one. Could use the even-more-optimized startsWithLettersIgnoringASCIICase.

> Source/WebKit/UIProcess/API/glib/InputMethodFilter.cpp:243
> +    auto cursorPositionUTF8 = cursorPosition != text.length() ? StringView(text).left(cursorPosition).utf8().length() : textUTF8.length();

Not great to call utf8().length() instead of an algorithm that can compute a UTF-8 length, without also allocating memory and copying the characters. But doesn’t need to be fixed right now.
Comment 4 Chris Dumez 2022-04-13 19:08:53 PDT
Created attachment 457586 [details]
Patch
Comment 5 Chris Dumez 2022-04-13 19:42:28 PDT
Created attachment 457588 [details]
Patch
Comment 6 EWS 2022-04-13 21:51:46 PDT
Committed r292857 (249628@main): <https://commits.webkit.org/249628@main>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 457588 [details].
Comment 7 Radar WebKit Bug Importer 2022-04-13 21:52:14 PDT
<rdar://problem/91734789>