diff options
author | Aliaksandr Valialkin <valyala@gmail.com> | 2016-02-19 12:53:39 +0200 |
---|---|---|
committer | Aliaksandr Valialkin <valyala@gmail.com> | 2016-02-19 12:53:39 +0200 |
commit | 5a26dcce53cbf2c6838027bf3531be9a75a1d6e8 (patch) | |
tree | 9bbd22fc2d792bacca7f3873b2d007e1936dfe78 /args.go | |
parent | Added LogAllErrors config parameter to Server, which allows logging the most ... (diff) | |
download | fasthttp-5a26dcce53cbf2c6838027bf3531be9a75a1d6e8.tar.gz fasthttp-5a26dcce53cbf2c6838027bf3531be9a75a1d6e8.tar.bz2 fasthttp-5a26dcce53cbf2c6838027bf3531be9a75a1d6e8.zip |
Added AcquireArgs and ReleaseArgs helper functions
Diffstat (limited to 'args.go')
-rw-r--r-- | args.go | 23 |
1 files changed, 23 insertions, 0 deletions
@@ -4,8 +4,31 @@ import ( "bytes" "errors" "io" + "sync" ) +// AcquireArgs returns an empty Args object from the pool. +// +// The returned Args may be returned to the pool with ReleaseArgs +// when no longer needed. This allows reducing GC load. +func AcquireArgs() *Args { + return argsPool.Get().(*Args) +} + +// ReleaseArgs returns the object acquired via AquireArgs to the pool. +// +// Do not access the released Args object, otherwise data races may occur. +func ReleaseArgs(a *Args) { + a.Reset() + argsPool.Put(a) +} + +var argsPool = &sync.Pool{ + New: func() interface{} { + return &Args{} + }, +} + // Args represents query arguments. // // It is forbidden copying Args instances. Create new instances instead |