Skip to content

Reduce branches in padding adjustment in FromBase64_ComputeResultLength #115022

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions src/libraries/System.Private.CoreLib/src/System/Convert.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2901,15 +2901,13 @@ private static unsafe int FromBase64_ComputeResultLength(char* inputPtr, int inp

// Perf: reuse the variable that stored the number of '=' to store the number of bytes encoded by the
// last group that contains the '=':
if (padding != 0)
padding = padding switch
{
if (padding == 1)
padding = 2;
else if (padding == 2)
padding = 1;
else
throw new FormatException(SR.Format_BadBase64Char);
}
0 => 0,
1 => 2,
2 => 1,
_ => throw new FormatException(SR.Format_BadBase64Char)
};

// Done:
return (usefulInputLength / 4) * 3 + padding;
Expand Down
Loading