mirror of
https://github.com/gin-gonic/gin.git
synced 2025-10-18 23:12:17 +08:00
update
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
This commit is contained in:
parent
1d5b9badd9
commit
31939986b9
15
tree.go
15
tree.go
@ -9,6 +9,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"unicode"
|
"unicode"
|
||||||
"unicode/utf8"
|
"unicode/utf8"
|
||||||
|
"unsafe"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Param is a single URL parameter, consisting of a key and a value.
|
// 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
|
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 {
|
type methodTree struct {
|
||||||
method string
|
method string
|
||||||
root *node
|
root *node
|
||||||
@ -163,7 +174,7 @@ walk:
|
|||||||
|
|
||||||
n.children = []*node{&child}
|
n.children = []*node{&child}
|
||||||
// []byte for proper unicode char conversion, see #65
|
// []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.path = path[:i]
|
||||||
n.handlers = nil
|
n.handlers = nil
|
||||||
n.wildChild = false
|
n.wildChild = false
|
||||||
@ -223,7 +234,7 @@ walk:
|
|||||||
// Otherwise insert it
|
// Otherwise insert it
|
||||||
if c != ':' && c != '*' {
|
if c != ':' && c != '*' {
|
||||||
// []byte for proper unicode char conversion, see #65
|
// []byte for proper unicode char conversion, see #65
|
||||||
n.indices += string([]byte{c})
|
n.indices += bytesToStr([]byte{c})
|
||||||
child := &node{
|
child := &node{
|
||||||
fullPath: fullPath,
|
fullPath: fullPath,
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user