From: Russ Cox Date: Thu, 21 Oct 2010 15:25:14 +0000 (-0400) Subject: encoding/binary: give LittleEndian, BigEndian specific types X-Git-Tag: weekly.2010-10-27~56 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=1451695f867773631763717d325f63093dbdda36;p=gostls13.git 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 --- 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