-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
atob() clones the output more than necessary #15781
atob() clones the output more than necessary #15781
Conversation
EWS run on previous version of this PR (hash e9e97e8) |
Methinks this patch works but maybe I misunderstood how base64 works. AFAICT, it should only use the following characters |
Source/WTF/wtf/text/Base64.cpp
Outdated
@@ -267,4 +268,18 @@ std::optional<Vector<uint8_t>> base64Decode(StringView input, Base64DecodeMode m | |||
return base64DecodeInternal(std::span(input.characters16(), length), mode); | |||
} | |||
|
|||
std::optional<String> base64DecodeToString(StringView input, Base64DecodeMode mode)\ | |||
{ | |||
auto toString = [&] (auto optionalBuffer) -> std::optional<String> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this PR really shows that we need to introduce a NonNullableString
in the codebase at some point or at least a Markable<String>
.
In the meantime, I guess we should use the isNull()
function instead of using an std::optional<String>
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, you're right. I was thinking for some reason that String::adopt
would return the nullString if given an empty vector but that's not the case. Will change the API.
e9e97e8
to
65fba56
Compare
EWS run on previous version of this PR (hash 65fba56) |
65fba56
to
f64e896
Compare
f64e896
to
bd645f8
Compare
EWS run on current version of this PR (hash bd645f8)
|
Base64 was created so that binary data could be sent as plain text (ASCII/Latin1). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
r=me
https://bugs.webkit.org/show_bug.cgi?id=258789 rdar://111993365 Reviewed by David Kilzer. Right now several users of `base64Decode` take the `Vector` returned and immediately convert it to a `String`. This conversion requires a copy as the `Vector` returned by `base64Decode` uses `VectorBufferMalloc` but `String` requires that the Vector backing store is malloced with `StringImplMalloc`. This patch simply adds a `base64DecodeToString` that calls `base64DecodeInternal` with a new template parameter telling `base64DecodeInternal` to use `StringImplMalloc`. Thus, avoiding the extra string copy. * Source/JavaScriptCore/jsc.cpp: (JSC_DEFINE_HOST_FUNCTION): * Source/WTF/wtf/text/Base64.cpp: (WTF::base64DecodeInternal): (WTF::base64DecodeToString): * Source/WTF/wtf/text/Base64.h: * Source/WTF/wtf/text/WTFString.h: * Source/WebCore/page/Base64Utilities.cpp: (WebCore::Base64Utilities::atob): * Source/WebCore/page/Page.cpp: (WebCore::Page::userStyleSheetLocationChanged): Canonical link: https://commits.webkit.org/266016@main
bd645f8
to
985e100
Compare
Committed 266016@main (985e100): https://commits.webkit.org/266016@main Reviewed commits have been landed. Closing PR #15781 and removing active labels. |
985e100
bd645f8
π§ͺ gtk-wk2π§ͺ api-gtk