From 4599419e690628dd798c8d037bba4efd8d0b7391 Mon Sep 17 00:00:00 2001 From: Josh Bleecher Snyder Date: Mon, 5 Mar 2018 07:40:26 -0800 Subject: [PATCH] debug/macho: use bytes.IndexByte instead of a loop Simpler, and no doubt faster. Change-Id: Idd401918da07a257de365087721e9ff061e6fd07 Reviewed-on: https://go-review.googlesource.com/98759 Run-TryBot: Josh Bleecher Snyder TryBot-Result: Gobot Gobot Reviewed-by: Ian Lance Taylor --- src/debug/macho/file.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/debug/macho/file.go b/src/debug/macho/file.go index 7b9e83e5a8..da5d9cad4c 100644 --- a/src/debug/macho/file.go +++ b/src/debug/macho/file.go @@ -545,8 +545,9 @@ func (f *File) pushSection(sh *Section, r io.ReaderAt) error { } func cstring(b []byte) string { - var i int - for i = 0; i < len(b) && b[i] != 0; i++ { + i := bytes.IndexByte(b, 0) + if i == -1 { + i = len(b) } return string(b[0:i]) } -- 2.50.0