]> Cypherpunks repositories - gostls13.git/commitdiff
os: use internal/byteorder
authorTobias Klauser <tklauser@distanz.ch>
Tue, 14 May 2024 11:22:07 +0000 (13:22 +0200)
committerGopher Robot <gobot@golang.org>
Tue, 14 May 2024 20:11:45 +0000 (20:11 +0000)
Change-Id: Ic88535f05a55966e35e5da7abb499aa5fadb5cc7
Reviewed-on: https://go-review.googlesource.com/c/go/+/585116
Reviewed-by: Ian Lance Taylor <iant@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Auto-Submit: Tobias Klauser <tobias.klauser@gmail.com>

src/os/dir_unix.go

index 7680be7799c0e6cd3e65ae34ad83f7a8c45c73dd..d8b4faa05788f0838b9a09c221c4853fccaafdb4 100644 (file)
@@ -7,6 +7,7 @@
 package os
 
 import (
+       "internal/byteorder"
        "internal/goarch"
        "io"
        "runtime"
@@ -174,15 +175,11 @@ func readIntBE(b []byte, size uintptr) uint64 {
        case 1:
                return uint64(b[0])
        case 2:
-               _ = b[1] // bounds check hint to compiler; see golang.org/issue/14808
-               return uint64(b[1]) | uint64(b[0])<<8
+               return uint64(byteorder.BeUint16(b))
        case 4:
-               _ = b[3] // bounds check hint to compiler; see golang.org/issue/14808
-               return uint64(b[3]) | uint64(b[2])<<8 | uint64(b[1])<<16 | uint64(b[0])<<24
+               return uint64(byteorder.BeUint32(b))
        case 8:
-               _ = b[7] // bounds check hint to compiler; see golang.org/issue/14808
-               return uint64(b[7]) | uint64(b[6])<<8 | uint64(b[5])<<16 | uint64(b[4])<<24 |
-                       uint64(b[3])<<32 | uint64(b[2])<<40 | uint64(b[1])<<48 | uint64(b[0])<<56
+               return uint64(byteorder.BeUint64(b))
        default:
                panic("syscall: readInt with unsupported size")
        }
@@ -193,15 +190,11 @@ func readIntLE(b []byte, size uintptr) uint64 {
        case 1:
                return uint64(b[0])
        case 2:
-               _ = b[1] // bounds check hint to compiler; see golang.org/issue/14808
-               return uint64(b[0]) | uint64(b[1])<<8
+               return uint64(byteorder.LeUint16(b))
        case 4:
-               _ = b[3] // bounds check hint to compiler; see golang.org/issue/14808
-               return uint64(b[0]) | uint64(b[1])<<8 | uint64(b[2])<<16 | uint64(b[3])<<24
+               return uint64(byteorder.LeUint32(b))
        case 8:
-               _ = b[7] // bounds check hint to compiler; see golang.org/issue/14808
-               return uint64(b[0]) | uint64(b[1])<<8 | uint64(b[2])<<16 | uint64(b[3])<<24 |
-                       uint64(b[4])<<32 | uint64(b[5])<<40 | uint64(b[6])<<48 | uint64(b[7])<<56
+               return uint64(byteorder.LeUint64(b))
        default:
                panic("syscall: readInt with unsupported size")
        }