diff options
author | Robert Griesemer <gri@golang.org> | 2009-12-28 15:48:58 -0800 |
---|---|---|
committer | Robert Griesemer <gri@golang.org> | 2009-12-28 15:48:58 -0800 |
commit | 9d07d37f317c2e58204c8aa2def2d8067133633b (patch) | |
tree | ff7b61fec4c9adb469ad8c067c4023194c1fade2 | |
parent | eb109a765d1ac7b99568b3185594cd8430de0684 (diff) | |
download | go-9d07d37f317c2e58204c8aa2def2d8067133633b.tar.gz go-9d07d37f317c2e58204c8aa2def2d8067133633b.zip |
A couple of tighter loops.
(I was looking at this code accidentally because of some gofmt
issues and thought that one could write this more effectively.
You may have deliberately chosen not to use ranges here to make
the index range clearer. Just let me know.)
R=agl, agl1
CC=golang-dev
https://golang.org/cl/181084
-rw-r--r-- | src/pkg/crypto/md5/md5.go | 20 |
1 files changed, 8 insertions, 12 deletions
diff --git a/src/pkg/crypto/md5/md5.go b/src/pkg/crypto/md5/md5.go index 2ee57f4214..fd0984a418 100644 --- a/src/pkg/crypto/md5/md5.go +++ b/src/pkg/crypto/md5/md5.go @@ -68,8 +68,8 @@ func (d *digest) Write(p []byte) (nn int, err os.Error) { n := _Block(d, p) p = p[n:] if len(p) > 0 { - for i := 0; i < len(p); i++ { - d.x[i] = p[i] + for i, x := range p { + d.x[i] = x } d.nx = len(p) } @@ -100,16 +100,12 @@ func (d *digest) Sum() []byte { p := make([]byte, 16) j := 0 - for i := 0; i < 4; i++ { - s := d.s[i] - p[j] = byte(s) - j++ - p[j] = byte(s >> 8) - j++ - p[j] = byte(s >> 16) - j++ - p[j] = byte(s >> 24) - j++ + for _, s := range d.s { + p[j+0] = byte(s >> 0) + p[j+1] = byte(s >> 8) + p[j+2] = byte(s >> 16) + p[j+3] = byte(s >> 24) + j += 4 } return p } |