I found the following code in crypto/sha256/sha256.go
:
func putUint32(x []byte, s uint32) {
_ = x[3]
x[0] = byte(s >> 24)
x[1] = byte(s >> 16)
x[2] = byte(s >> 8)
x[3] = byte(s)
}
All I see that this assignment to the blank identifier would do is panic if len(x)
wasn't at least 4, which isn't even an effect of the assignment as much as it is of the evaluation of x[3]
. So, wouldn't the following (shorter, more desirable code) be equivalent?
func putUint32(x []byte, s uint32) {
x[3] = byte(s)
x[2] = byte(s >> 8)
x[1] = byte(s >> 16)
x[0] = byte(s >> 24)
}
If so, why wasn't it written this way?