diff options
author | ZYunH <zyunhjob@163.com> | 2019-08-19 16:45:03 +0800 |
---|---|---|
committer | Erik Dubbelboer <erik@dubbelboer.com> | 2019-08-19 10:45:03 +0200 |
commit | c5413ffda8a3203d573900b871da46234fcf9466 (patch) | |
tree | 3c73a3be01787fa3bae40291df31007ac48852cc /bytesconv.go | |
parent | Add ability to set timeout for handshake (#631) (diff) | |
download | fasthttp-c5413ffda8a3203d573900b871da46234fcf9466.tar.gz fasthttp-c5413ffda8a3203d573900b871da46234fcf9466.tar.bz2 fasthttp-c5413ffda8a3203d573900b871da46234fcf9466.zip |
A faster s2b function (#637)
* Use pointer for smaller stack space
Diffstat (limited to 'bytesconv.go')
-rw-r--r-- | bytesconv.go | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/bytesconv.go b/bytesconv.go index 8c0e154..7a98031 100644 --- a/bytesconv.go +++ b/bytesconv.go @@ -384,14 +384,13 @@ func b2s(b []byte) string { // // Note it may break if string and/or slice header will change // in the future go versions. -func s2b(s string) []byte { - sh := (*reflect.StringHeader)(unsafe.Pointer(&s)) - bh := reflect.SliceHeader{ - Data: sh.Data, - Len: sh.Len, - Cap: sh.Len, - } - return *(*[]byte)(unsafe.Pointer(&bh)) +func s2b(s string) (b []byte) { + bh := (*reflect.SliceHeader)(unsafe.Pointer(&b)) + sh := *(*reflect.StringHeader)(unsafe.Pointer(&s)) + bh.Data = sh.Data + bh.Len = sh.Len + bh.Cap = sh.Len + return b } // AppendUnquotedArg appends url-decoded src to dst and returns appended dst. |