Commit 41818f8f authored by Rui Ueyama's avatar Rui Ueyama Committed by Nigel Tao

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
parent 108a4dcd
......@@ -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:]
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment