aboutsummaryrefslogtreecommitdiff
path: root/args.go
diff options
context:
space:
mode:
authorGravatar Aliaksandr Valialkin <valyala@gmail.com> 2016-02-19 12:53:39 +0200
committerGravatar Aliaksandr Valialkin <valyala@gmail.com> 2016-02-19 12:53:39 +0200
commit5a26dcce53cbf2c6838027bf3531be9a75a1d6e8 (patch)
tree9bbd22fc2d792bacca7f3873b2d007e1936dfe78 /args.go
parentAdded LogAllErrors config parameter to Server, which allows logging the most ... (diff)
downloadfasthttp-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.go23
1 files changed, 23 insertions, 0 deletions
diff --git a/args.go b/args.go
index cd9bb9e..92f8e4c 100644
--- a/args.go
+++ b/args.go
@@ -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