diff options
Diffstat (limited to 'libgo/go/encoding/base32/base32.go')
-rw-r--r-- | libgo/go/encoding/base32/base32.go | 52 |
1 files changed, 22 insertions, 30 deletions
diff --git a/libgo/go/encoding/base32/base32.go b/libgo/go/encoding/base32/base32.go index 3fb6cac..e14d2d4 100644 --- a/libgo/go/encoding/base32/base32.go +++ b/libgo/go/encoding/base32/base32.go @@ -284,7 +284,12 @@ func (e CorruptInputError) Error() string { // additional data is an error. This method assumes that src has been // stripped of all supported whitespace ('\r' and '\n'). func (enc *Encoding) decode(dst, src []byte) (n int, end bool, err error) { + // Lift the nil check outside of the loop. + _ = enc.decodeMap + + dsti := 0 olen := len(src) + for len(src) > 0 && !end { // Decode quantum using the base32 alphabet var dbuf [8]byte @@ -292,17 +297,15 @@ func (enc *Encoding) decode(dst, src []byte) (n int, end bool, err error) { for j := 0; j < 8; { - // We have reached the end and are missing padding - if len(src) == 0 && enc.padChar != NoPadding { - return n, false, CorruptInputError(olen - len(src) - j) - } - - // We have reached the end and are not expecing any padding - if len(src) == 0 && enc.padChar == NoPadding { + if len(src) == 0 { + if enc.padChar != NoPadding { + // We have reached the end and are missing padding + return n, false, CorruptInputError(olen - len(src) - j) + } + // We have reached the end and are not expecing any padding dlen, end = j, true break } - in := src[0] src = src[1:] if in == byte(enc.padChar) && j >= 2 && len(src) < 8 { @@ -339,37 +342,26 @@ func (enc *Encoding) decode(dst, src []byte) (n int, end bool, err error) { // quantum switch dlen { case 8: - dst[4] = dbuf[6]<<5 | dbuf[7] + dst[dsti+4] = dbuf[6]<<5 | dbuf[7] + n++ fallthrough case 7: - dst[3] = dbuf[4]<<7 | dbuf[5]<<2 | dbuf[6]>>3 + dst[dsti+3] = dbuf[4]<<7 | dbuf[5]<<2 | dbuf[6]>>3 + n++ fallthrough case 5: - dst[2] = dbuf[3]<<4 | dbuf[4]>>1 + dst[dsti+2] = dbuf[3]<<4 | dbuf[4]>>1 + n++ fallthrough case 4: - dst[1] = dbuf[1]<<6 | dbuf[2]<<1 | dbuf[3]>>4 + dst[dsti+1] = dbuf[1]<<6 | dbuf[2]<<1 | dbuf[3]>>4 + n++ fallthrough case 2: - dst[0] = dbuf[0]<<3 | dbuf[1]>>2 - } - - if !end { - dst = dst[5:] - } - - switch dlen { - case 2: - n += 1 - case 4: - n += 2 - case 5: - n += 3 - case 7: - n += 4 - case 8: - n += 5 + dst[dsti+0] = dbuf[0]<<3 | dbuf[1]>>2 + n++ } + dsti += 5 } return n, end, nil } |