refactor(variable): 简化变量池函数
- PoolGet() 改为调用 NewContext() - PoolPut() 改为调用 ReleaseContext() - 添加 Deprecated 文档注释 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
4d608c4284
commit
4a93cf2b5c
@ -40,23 +40,10 @@ func GetPool() *sync.Pool {
|
||||
}
|
||||
|
||||
// PoolGet 从池中获取 Context(包装方法,用于统计)
|
||||
//
|
||||
// Deprecated: 使用 NewContext 代替,该函数保持向后兼容。
|
||||
func PoolGet(ctx *fasthttp.RequestCtx) *Context {
|
||||
vc := pool.Get().(*Context)
|
||||
|
||||
// 初始化
|
||||
vc.ctx = ctx
|
||||
vc.status = 0
|
||||
vc.bodySize = 0
|
||||
vc.duration = 0
|
||||
vc.serverName = ""
|
||||
|
||||
// 清空缓存和自定义变量
|
||||
for k := range vc.cache {
|
||||
delete(vc.cache, k)
|
||||
}
|
||||
for k := range vc.store {
|
||||
delete(vc.store, k)
|
||||
}
|
||||
vc := NewContext(ctx)
|
||||
|
||||
// 更新统计
|
||||
statsMu.Lock()
|
||||
@ -68,19 +55,14 @@ func PoolGet(ctx *fasthttp.RequestCtx) *Context {
|
||||
}
|
||||
|
||||
// PoolPut 将 Context 放回池中(包装方法,用于统计)
|
||||
//
|
||||
// Deprecated: 使用 ReleaseContext 代替,该函数保持向后兼容。
|
||||
func PoolPut(vc *Context) {
|
||||
if vc == nil {
|
||||
return
|
||||
}
|
||||
|
||||
// 清理引用
|
||||
vc.ctx = nil
|
||||
vc.status = 0
|
||||
vc.bodySize = 0
|
||||
vc.duration = 0
|
||||
vc.serverName = ""
|
||||
|
||||
pool.Put(vc)
|
||||
ReleaseContext(vc)
|
||||
|
||||
// 更新统计
|
||||
statsMu.Lock()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user