From 31939986b97cd5e59aa05c26250e5570804a93c0 Mon Sep 17 00:00:00 2001 From: Bo-Yi Wu Date: Sun, 17 May 2020 02:04:10 +0800 Subject: [PATCH] update Signed-off-by: Bo-Yi Wu --- tree.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/tree.go b/tree.go index f528fa3b..98581b9c 100644 --- a/tree.go +++ b/tree.go @@ -9,6 +9,7 @@ import ( "strings" "unicode" "unicode/utf8" + "unsafe" ) // Param is a single URL parameter, consisting of a key and a value. @@ -40,6 +41,16 @@ func (ps Params) ByName(name string) (va string) { return } +func strToBytes(s string) []byte { + x := (*[2]uintptr)(unsafe.Pointer(&s)) + h := [3]uintptr{x[0], x[1], x[1]} + return *(*[]byte)(unsafe.Pointer(&h)) +} + +func bytesToStr(b []byte) string { + return *(*string)(unsafe.Pointer(&b)) +} + type methodTree struct { method string root *node @@ -163,7 +174,7 @@ walk: n.children = []*node{&child} // []byte for proper unicode char conversion, see #65 - n.indices = string([]byte{n.path[i]}) + n.indices = bytesToStr([]byte{n.path[i]}) n.path = path[:i] n.handlers = nil n.wildChild = false @@ -223,7 +234,7 @@ walk: // Otherwise insert it if c != ':' && c != '*' { // []byte for proper unicode char conversion, see #65 - n.indices += string([]byte{c}) + n.indices += bytesToStr([]byte{c}) child := &node{ fullPath: fullPath, }