]> Cypherpunks repositories - gostls13.git/commit
encoding/binary: give LittleEndian, BigEndian specific types
authorRuss Cox <rsc@golang.org>
Thu, 21 Oct 2010 15:25:14 +0000 (11:25 -0400)
committerRuss Cox <rsc@golang.org>
Thu, 21 Oct 2010 15:25:14 +0000 (11:25 -0400)
commit1451695f867773631763717d325f63093dbdda36
tree904a79640d9c40c859c0c097c9b7e90947a3fbd1
parent4f6fb1b7753d84fb45f4cc44589ffffdc6fcfc52
encoding/binary: give LittleEndian, BigEndian specific types

Giving them specific types has the benefit that
binary.BigEndian.Uint32(b) is now a direct call, not an
indirect via a mutable interface value, so it can potentially
be inlined.

Recent changes to the spec relaxed the rules for comparison,
so this code is still valid:

func isLittle(o binary.ByteOrder) { return o == binary.LittleEndian }

The change does break this potential idiom:

o := binary.BigEndian
if foo {
o = binary.LittleEndian
}

That must rewrite to give o an explicit binary.ByteOrder type.
On balance I think the benefit from the direct call and inlining
outweigh the cost of breaking that idiom.

R=r, r2
CC=golang-dev
https://golang.org/cl/2427042
src/pkg/encoding/binary/binary.go