Bug 258789 - atob() clones the output more than necessary
Summary: atob() clones the output more than necessary
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebCore JavaScript (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Keith Miller
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2023-07-02 20:04 PDT by Jarred Sumner
Modified: 2023-07-12 17:17 PDT (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jarred Sumner 2023-07-02 20:04:29 PDT
From: https://github.com/WebKit/WebKit/blob/de456d04c10080ce71f48d14b3a9d278854d5f8a/Source/WebCore/page/Base64Utilities.cpp#L53


    auto decodedData = base64Decode(encodedString, Base64DecodeMode::DefaultValidatePaddingAndIgnoreWhitespace);
    if (!decodedData)
        return Exception { InvalidCharacterError };

    return String(decodedData->data(), decodedData->size());


String(const char*, unsigned) calls StringImpl::create(reinterpret_cast<const LChar*>(ptr), length).

This is an extra clone, from the Vector<uint8_t> -> StringImpl. Seems like moving the Vector would also clone it.

Possible suggestions:
- base64Decode could have a template arg to use WTF::StringBuilder?
- Maybe there's a way using ExternalStringImpl?
Comment 1 Radar WebKit Bug Importer 2023-07-09 20:05:15 PDT
<rdar://problem/111993365>
Comment 2 Keith Miller 2023-07-12 09:53:59 PDT
Pull request: https://github.com/WebKit/WebKit/pull/15781
Comment 3 EWS 2023-07-12 17:17:47 PDT
Committed 266016@main (985e10033996): <https://commits.webkit.org/266016@main>

Reviewed commits have been landed. Closing PR #15781 and removing active labels.