mirror of
https://github.com/astaxie/beego.git
synced 2024-11-26 04:01:29 +00:00
reduce the slicegrow
This commit is contained in:
parent
29752e2575
commit
dbc4ac6945
@ -50,7 +50,8 @@ type BeegoInput struct {
|
|||||||
// NewInput return BeegoInput generated by Context.
|
// NewInput return BeegoInput generated by Context.
|
||||||
func NewInput() *BeegoInput {
|
func NewInput() *BeegoInput {
|
||||||
return &BeegoInput{
|
return &BeegoInput{
|
||||||
pvalues: make([]string, maxParam),
|
pnames: make([]string, 0, maxParam),
|
||||||
|
pvalues: make([]string, 0, maxParam),
|
||||||
data: make(map[interface{}]interface{}),
|
data: make(map[interface{}]interface{}),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -60,6 +61,7 @@ func (input *BeegoInput) Reset(ctx *Context) {
|
|||||||
input.Context = ctx
|
input.Context = ctx
|
||||||
input.CruSession = nil
|
input.CruSession = nil
|
||||||
input.pnames = input.pnames[:0]
|
input.pnames = input.pnames[:0]
|
||||||
|
input.pvalues = input.pvalues[:0]
|
||||||
input.data = nil
|
input.data = nil
|
||||||
input.RequestBody = []byte{}
|
input.RequestBody = []byte{}
|
||||||
}
|
}
|
||||||
@ -264,7 +266,7 @@ func (input *BeegoInput) ParamsLen() int {
|
|||||||
// Param returns router param by a given key.
|
// Param returns router param by a given key.
|
||||||
func (input *BeegoInput) Param(key string) string {
|
func (input *BeegoInput) Param(key string) string {
|
||||||
for i, v := range input.pnames {
|
for i, v := range input.pnames {
|
||||||
if v == key {
|
if v == key && i <= len(input.pvalues) {
|
||||||
return input.pvalues[i]
|
return input.pvalues[i]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -273,7 +275,7 @@ func (input *BeegoInput) Param(key string) string {
|
|||||||
|
|
||||||
// SetParam will set the param with key and value
|
// SetParam will set the param with key and value
|
||||||
func (input *BeegoInput) SetParam(key, val string) {
|
func (input *BeegoInput) SetParam(key, val string) {
|
||||||
input.pvalues[len(input.pnames)] = val
|
input.pvalues = append(input.pvalues, val)
|
||||||
input.pnames = append(input.pnames, key)
|
input.pnames = append(input.pnames, key)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
3
tree.go
3
tree.go
@ -288,7 +288,8 @@ func (t *Tree) Match(pattern string, ctx *context.Context) (runObject interface{
|
|||||||
if len(pattern) == 0 || pattern[0] != '/' {
|
if len(pattern) == 0 || pattern[0] != '/' {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return t.match(pattern, nil, ctx)
|
w := make([]string, 0, 20)
|
||||||
|
return t.match(pattern, w, ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *Tree) match(pattern string, wildcardValues []string, ctx *context.Context) (runObject interface{}) {
|
func (t *Tree) match(pattern string, wildcardValues []string, ctx *context.Context) (runObject interface{}) {
|
||||||
|
Loading…
Reference in New Issue
Block a user