From e439b1326b3264f9271b6baadbcea3b8147e26f3 Mon Sep 17 00:00:00 2001 From: qiulaidongfeng <2645477756@qq.com> Date: Mon, 5 Feb 2024 14:38:37 +0800 Subject: [PATCH] gopls/internal/util/frob: use binary.LittleEndian.AppendUint{16,32,64} Complete a TODO. Change-Id: I5ef391754d516a9a7672308e1f7e829789f6ac2e --- gopls/internal/util/frob/frob.go | 37 +++----------------------------- 1 file changed, 3 insertions(+), 34 deletions(-) diff --git a/gopls/internal/util/frob/frob.go b/gopls/internal/util/frob/frob.go index 0f3ede26773..d086d0e6409 100644 --- a/gopls/internal/util/frob/frob.go +++ b/gopls/internal/util/frob/frob.go @@ -402,38 +402,7 @@ func (r *reader) bytes(n int) []byte { type writer struct{ data []byte } func (w *writer) uint8(v uint8) { w.data = append(w.data, v) } -func (w *writer) uint16(v uint16) { w.data = appendUint16(w.data, v) } -func (w *writer) uint32(v uint32) { w.data = appendUint32(w.data, v) } -func (w *writer) uint64(v uint64) { w.data = appendUint64(w.data, v) } +func (w *writer) uint16(v uint16) { w.data = binary.LittleEndian.AppendUint16(w.data, v) } +func (w *writer) uint32(v uint32) { w.data = binary.LittleEndian.AppendUint32(w.data, v) } +func (w *writer) uint64(v uint64) { w.data = binary.LittleEndian.AppendUint64(w.data, v) } func (w *writer) bytes(v []byte) { w.data = append(w.data, v...) } - -// TODO(adonovan): delete these as in go1.19 they are methods on LittleEndian: - -func appendUint16(b []byte, v uint16) []byte { - return append(b, - byte(v), - byte(v>>8), - ) -} - -func appendUint32(b []byte, v uint32) []byte { - return append(b, - byte(v), - byte(v>>8), - byte(v>>16), - byte(v>>24), - ) -} - -func appendUint64(b []byte, v uint64) []byte { - return append(b, - byte(v), - byte(v>>8), - byte(v>>16), - byte(v>>24), - byte(v>>32), - byte(v>>40), - byte(v>>48), - byte(v>>56), - ) -}