Skip to content
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

src: avoid allocation in the Size method for BASE64URL and BASE64 #53550

Closed
wants to merge 16 commits into from
23 changes: 8 additions & 15 deletions src/string_bytes.cc
Original file line number Diff line number Diff line change
Expand Up @@ -449,12 +449,10 @@ Maybe<size_t> StringBytes::StorageSize(Isolate* isolate,
break;

case BASE64URL:
data_size = simdutf::base64_length_from_binary(str->Length(),
simdutf::base64_url);
break;

case BASE64:
data_size = simdutf::base64_length_from_binary(str->Length());
data_size = str->Length() % 4 <= 1
? str->Length() / 4 * 3
: str->Length() / 4 * 3 + (str->Length() % 4) - 1;
mildsunrise marked this conversation as resolved.
Show resolved Hide resolved
break;

case HEX:
Expand Down Expand Up @@ -493,16 +491,11 @@ Maybe<size_t> StringBytes::Size(Isolate* isolate,
case UCS2:
return Just(str->Length() * sizeof(uint16_t));

case BASE64URL: {
String::Value value(isolate, str);
return Just(simdutf::base64_length_from_binary(value.length(),
simdutf::base64_url));
}

case BASE64: {
String::Value value(isolate, str);
return Just(simdutf::base64_length_from_binary(value.length()));
}
case BASE64URL:
case BASE64:
return Just<size_t>(str->Length() % 4 <= 1 ? str->Length() / 4 * 3
: str->Length() / 4 * 3 +
(str->Length() % 4) - 1);

case HEX:
return Just<size_t>(str->Length() / 2);
Expand Down
Loading