1
0
mirror of https://github.com/golang/go synced 2024-11-18 08:44:43 -07:00

base64: refactor encoder.Write

"nn" can never be zero for any input "p", so no check is needed.
This change should improve readability a bit.

LGTM=nigeltao
R=golang-codereviews, bradfitz, nigeltao
CC=golang-codereviews
https://golang.org/cl/76610045
This commit is contained in:
Rui Ueyama 2014-03-18 16:26:23 +11:00 committed by Nigel Tao
parent 108a4dcd75
commit 41818f8fcc

View File

@ -159,13 +159,11 @@ func (e *encoder) Write(p []byte) (n int, err error) {
nn := len(e.out) / 4 * 3
if nn > len(p) {
nn = len(p)
nn -= nn % 3
}
nn -= nn % 3
if nn > 0 {
e.enc.Encode(e.out[0:], p[0:nn])
if _, e.err = e.w.Write(e.out[0 : nn/3*4]); e.err != nil {
return n, e.err
}
e.enc.Encode(e.out[0:], p[0:nn])
if _, e.err = e.w.Write(e.out[0 : nn/3*4]); e.err != nil {
return n, e.err
}
n += nn
p = p[nn:]