Bug 239306 - Replace calls to substring(0, x) with the more concise left(x)
Summary: Replace calls to substring(0, x) with the more concise left(x)
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebCore Misc. (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Chris Dumez
URL:
Keywords: InRadar
Depends on:
Blocks: 239289
  Show dependency treegraph
 
Reported: 2022-04-13 15:27 PDT by Chris Dumez
Modified: 2022-04-13 21:52 PDT (History)
2 users (show)

See Also:


Attachments
Patch (92.36 KB, patch)
2022-04-13 16:14 PDT, Chris Dumez
ews-feeder: commit-queue-
Details | Formatted Diff | Diff
Patch (92.43 KB, patch)
2022-04-13 17:14 PDT, Chris Dumez
no flags Details | Formatted Diff | Diff
Patch (93.09 KB, patch)
2022-04-13 19:08 PDT, Chris Dumez
ews-feeder: commit-queue-
Details | Formatted Diff | Diff
Patch (93.12 KB, patch)
2022-04-13 19:42 PDT, Chris Dumez
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
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>