diff options
| author | Russ Cox <rsc@golang.org> | 2010-10-21 11:25:14 -0400 |
|---|---|---|
| committer | Russ Cox <rsc@golang.org> | 2010-10-21 11:25:14 -0400 |
| commit | 1451695f867773631763717d325f63093dbdda36 (patch) | |
| tree | 904a79640d9c40c859c0c097c9b7e90947a3fbd1 /src/pkg/encoding/binary | |
| parent | 4f6fb1b7753d84fb45f4cc44589ffffdc6fcfc52 (diff) | |
| download | go-1451695f867773631763717d325f63093dbdda36.tar.xz | |
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
Diffstat (limited to 'src/pkg/encoding/binary')
| -rw-r--r-- | src/pkg/encoding/binary/binary.go | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/src/pkg/encoding/binary/binary.go b/src/pkg/encoding/binary/binary.go index 2343e0398b..ebc2ae8b7c 100644 --- a/src/pkg/encoding/binary/binary.go +++ b/src/pkg/encoding/binary/binary.go @@ -29,8 +29,11 @@ type ByteOrder interface { // allowing, e.g., order == binary.LittleEndian. type unused byte -var LittleEndian ByteOrder = littleEndian(0) -var BigEndian ByteOrder = bigEndian(0) +// LittleEndian is the little-endian implementation of ByteOrder. +var LittleEndian littleEndian + +// BigEndian is the big-endian implementation of ByteOrder. +var BigEndian bigEndian type littleEndian unused |
