aboutsummaryrefslogtreecommitdiff
path: root/bytesconv.go
diff options
context:
space:
mode:
authorGravatar Aliaksandr Valialkin <valyala@gmail.com> 2016-06-07 13:29:51 +0300
committerGravatar Aliaksandr Valialkin <valyala@gmail.com> 2016-06-07 13:30:03 +0300
commit033bb40f06c5c88ffa4f12c26b4eb3d8a15403b0 (patch)
tree8fc77756b5892a2ddbbfd85c5bf86d8f1ef33bf5 /bytesconv.go
parentLimit the number of concurrently running request handlers inside TimeoutHandler (diff)
downloadfasthttp-033bb40f06c5c88ffa4f12c26b4eb3d8a15403b0.tar.gz
fasthttp-033bb40f06c5c88ffa4f12c26b4eb3d8a15403b0.tar.bz2
fasthttp-033bb40f06c5c88ffa4f12c26b4eb3d8a15403b0.zip
Properly handle hashes and single dots in URI.Update (see https://github.com/kataras/iris/issues/173)
Diffstat (limited to 'bytesconv.go')
-rw-r--r--bytesconv.go15
1 files changed, 15 insertions, 0 deletions
diff --git a/bytesconv.go b/bytesconv.go
index 5f39dcc..13ce724 100644
--- a/bytesconv.go
+++ b/bytesconv.go
@@ -8,6 +8,7 @@ import (
"io"
"math"
"net"
+ "reflect"
"sync"
"time"
"unsafe"
@@ -360,6 +361,20 @@ func b2s(b []byte) string {
return *(*string)(unsafe.Pointer(&b))
}
+// s2b converts string to a byte slice without memory allocation.
+//
+// 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))
+}
+
// AppendQuotedArg appends url-encoded src to dst and returns appended dst.
func AppendQuotedArg(dst, src []byte) []byte {
for _, c := range src {