mirror of
https://github.com/gin-gonic/gin.git
synced 2025-10-15 13:02:14 +08:00
Optimize the Copy method of the Context struct: using 'make' to initialize the map('cp.Keys') with a length of 'c.Keys'; avoiding repeatedly assiging the 'params' to 'context'.
This commit is contained in:
parent
ecdbbbe948
commit
48e6fd723d
@ -113,20 +113,19 @@ func (c *Context) Copy() *Context {
|
||||
cp := Context{
|
||||
writermem: c.writermem,
|
||||
Request: c.Request,
|
||||
Params: c.Params,
|
||||
engine: c.engine,
|
||||
}
|
||||
cp.writermem.ResponseWriter = nil
|
||||
cp.Writer = &cp.writermem
|
||||
cp.index = abortIndex
|
||||
cp.handlers = nil
|
||||
cp.Keys = map[string]any{}
|
||||
cp.Keys = make(map[string]any, len(c.Keys))
|
||||
for k, v := range c.Keys {
|
||||
cp.Keys[k] = v
|
||||
}
|
||||
paramCopy := make([]Param, len(cp.Params))
|
||||
copy(paramCopy, cp.Params)
|
||||
cp.Params = paramCopy
|
||||
paramsCopy := make([]Param, len(c.Params))
|
||||
copy(paramsCopy, c.Params)
|
||||
cp.Params = paramsCopy
|
||||
return &cp
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user