From 1451695f867773631763717d325f63093dbdda36 Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Thu, 21 Oct 2010 11:25:14 -0400 Subject: [PATCH] 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 | 7 +++++-- 1 file 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 -- 2.50.0