From e64a828a1ba8558ed373814d800ec1cbf620e201 Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Thu, 8 Mar 2018 13:23:47 +0100 Subject: [PATCH] unix: use bytes.IndexByte instead of a for loop Change-Id: I43bf3a7eafbf06b20a589ee339dae394bfea0bf6 Reviewed-on: https://go-review.googlesource.com/99515 Run-TryBot: Tobias Klauser TryBot-Result: Gobot Gobot Reviewed-by: Brad Fitzpatrick --- unix/syscall_unix.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/unix/syscall_unix.go b/unix/syscall_unix.go index cd8f3a9c..80b05a40 100644 --- a/unix/syscall_unix.go +++ b/unix/syscall_unix.go @@ -7,6 +7,7 @@ package unix import ( + "bytes" "runtime" "sync" "syscall" @@ -52,12 +53,11 @@ func errnoErr(e syscall.Errno) error { // clen returns the index of the first NULL byte in n or len(n) if n contains no NULL byte. func clen(n []byte) int { - for i := 0; i < len(n); i++ { - if n[i] == 0 { - return i - } + i := bytes.IndexByte(n, 0) + if i == -1 { + i = len(n) } - return len(n) + return i } // Mmap manager, for use by operating system-specific implementations.