Skip to content
Myr

Remove some functions that have the same effect as the bytes package (#2387)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by bestgopher · committed by GitHub · parent acbb3d4 · Browse files · 1 file+9 added−33 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+9 added−33 removed

  • other:+9 added−33 removed

1 file+9 added−33 removed

modified:tree.go+9 added-33 removed
5 unmodified lines
67import (8 "bytes"9 "net/url"10 "reflect"10 "strings"11 "unicode"12 "unicode/utf8"14 "unsafe"1314 "github.com/gin-gonic/gin/internal/bytesconv"15)1617var (18 strColon = []byte(":")
60 unmodified lines
79 }80 return i81}8283// bytesToStr converts byte slice to a string without memory allocation.84// See https://groups.google.com/forum/#!msg/Golang-Nuts/ENgbUzYvCuU/90yGx7GUAgAJ .85//86// Note it may break if string and/or slice header will change87// in the future go versions.88func bytesToStr(b []byte) string {89 return *(*string)(unsafe.Pointer(&b))90}9192// strToBytes converts string to a byte slice without memory allocation.93//94// Note it may break if string and/or slice header will change95// in the future go versions.96func strToBytes(s string) (b []byte) {97 /* #nosec G103 */98 bh := (*reflect.SliceHeader)(unsafe.Pointer(&b))99 /* #nosec G103 */100 sh := *(*reflect.StringHeader)(unsafe.Pointer(&s))101 bh.Data = sh.Data102 bh.Len = sh.Len103 bh.Cap = sh.Len104 return b105}10683func countParams(path string) uint16 {108 var n uint109 s := strToBytes(path)110 n += uint(bytes.Count(s, strColon))111 n += uint(bytes.Count(s, strStar))112 return uint16(n)84 var n uint1685 s := bytesconv.StringToBytes(path)86 n += uint16(bytes.Count(s, strColon))87 n += uint16(bytes.Count(s, strStar))88 return n89}9091type nodeType uint892
74 unmodified lines
167 }168169 n.children = []*node{&child}170 // []byte for proper unicode char conversion, see #65195 n.indices = bytesToStr([]byte{n.path[i]})171 n.indices = bytesconv.BytesToString([]byte{n.path[i]})172 n.path = path[:i]173 n.handlers = nil174 n.wildChild = false175 n.fullPath = fullPath[:parentFullPathIndex+i]
51 unmodified lines
227228 // Otherwise insert it229 if c != ':' && c != '*' {230 // []byte for proper unicode char conversion, see #65255 n.indices += bytesToStr([]byte{c})231 n.indices += bytesconv.BytesToString([]byte{c})232 child := &node{233 fullPath: fullPath,234 }235 n.children = append(n.children, child)
540 unmodified lines