Skip to content

Commit

Permalink
perf(base64): Avoid unnecessary calculations
Browse files Browse the repository at this point in the history
  • Loading branch information
gibson042 committed Jan 22, 2024
1 parent 061a9d7 commit b507be4
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/base64/src/decode.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@ export const jsDecodeBase64 = (string, name = '<unknown>') => {
i += 1;
}

while (quantum % 8 !== 0) {
while (quantum > 0) {
if (i === string.length || string[i] !== padding) {
throw Error(`Missing padding at offset ${i} of string ${name}`);
}
// We MAY reject non-zero padding bits, but choose not to.
// https://datatracker.ietf.org/doc/html/rfc4648#section-3.5
i += 1;
quantum += 6;
quantum -= 2;
}

if (i < string.length) {
Expand Down

0 comments on commit b507be4

Please sign in to comment.