From 690db104634afb5c5840a08881ea1b70e24eb32b Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Sat, 23 Mar 2024 17:39:59 -0400 Subject: [PATCH] AK: Convert Base64 template parameters to regular function parameters The generated function name is otherwise very long, which makes stack traces a bit more difficult to sift through. --- AK/Base64.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/AK/Base64.cpp b/AK/Base64.cpp index 9302241e687..1ec9701b083 100644 --- a/AK/Base64.cpp +++ b/AK/Base64.cpp @@ -24,8 +24,7 @@ size_t calculate_base64_encoded_length(ReadonlyBytes input) return ((4 * input.size() / 3) + 3) & ~3; } -template -ErrorOr decode_base64_impl(StringView input) +static ErrorOr decode_base64_impl(StringView input, ReadonlySpan alphabet_lookup_table) { auto get = [&](size_t& offset, bool* is_padding, bool& parsed_something) -> ErrorOr { while (offset < input.length() && is_ascii_space(input[offset])) @@ -82,8 +81,7 @@ ErrorOr decode_base64_impl(StringView input) return output; } -template -ErrorOr encode_base64_impl(ReadonlyBytes input) +static ErrorOr encode_base64_impl(ReadonlyBytes input, ReadonlySpan alphabet) { Vector output; TRY(output.try_ensure_capacity(calculate_base64_encoded_length(input))); @@ -121,21 +119,23 @@ ErrorOr encode_base64_impl(ReadonlyBytes input) ErrorOr decode_base64(StringView input) { - return decode_base64_impl(input); + static constexpr auto lookup_table = base64_lookup_table(); + return decode_base64_impl(input, lookup_table); } ErrorOr decode_base64url(StringView input) { - return decode_base64_impl(input); + static constexpr auto lookup_table = base64url_lookup_table(); + return decode_base64_impl(input, lookup_table); } ErrorOr encode_base64(ReadonlyBytes input) { - return encode_base64_impl(input); + return encode_base64_impl(input, base64_alphabet); } ErrorOr encode_base64url(ReadonlyBytes input) { - return encode_base64_impl(input); + return encode_base64_impl(input, base64url_alphabet); } }