unix: use bytes.IndexByte instead of a for loop

Change-Id: I43bf3a7eafbf06b20a589ee339dae394bfea0bf6
Reviewed-on: https://go-review.googlesource.com/99515
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
Tobias Klauser
2018-03-08 15:16:43 +00:00
committed by Tobias Klauser
parent 349b81fb5c
commit e64a828a1b
+5 -5
View File
@@ -7,6 +7,7 @@
package unix package unix
import ( import (
"bytes"
"runtime" "runtime"
"sync" "sync"
"syscall" "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. // 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 { func clen(n []byte) int {
for i := 0; i < len(n); i++ { i := bytes.IndexByte(n, 0)
if n[i] == 0 { if i == -1 {
return i i = len(n)
}
} }
return len(n) return i
} }
// Mmap manager, for use by operating system-specific implementations. // Mmap manager, for use by operating system-specific implementations.