]> Cypherpunks repositories - gostls13.git/commit
syscall: optimize Byte{Ptr,Slice}FromString
authorKir Kolyshkin <kolyshkin@gmail.com>
Thu, 2 Dec 2021 03:48:58 +0000 (19:48 -0800)
committerEmmanuel Odeke <emmanuel@orijtech.com>
Mon, 28 Mar 2022 16:55:57 +0000 (16:55 +0000)
commit0d651041a9f48bbd1456317dfc784cdfa253e877
treeecd2e945e2adf25d1956b87fe2f7ee8e5cb25f4f
parentd6a1ffd624bd0d6dbf3a15070e378749612b35c9
syscall: optimize Byte{Ptr,Slice}FromString

Use bytealg.IndexByteString(str, 0) instead of looping through the
string to check for a zero byte. A quick and dirty benchmark shows 10x
performance improvement (on amd64 machine, using go 1.17.3).

BytePtrFromString is used by many functions with string arguments.
This change should make many functions in os package, such as those
accepting a filename (os.Open, os.Stat, etc.), a tad faster.

PS I am aware that syscall package is deprecated and frozen, but this
change is mainly for the os package and the likes. The alternative
would be for os to switch to x/sys, which is a much bigger change.

Change-Id: I18fdd50f9fbfe0a23a4a71bc4bd0a5f5b0eaa475
Reviewed-on: https://go-review.googlesource.com/c/go/+/368457
Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: Emmanuel Odeke <emmanuel@orijtech.com>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
src/syscall/syscall.go