Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2882)

Unified Diff: common/chunkstream/chunkNodePool.go

Issue 1413923013: Add `chunk` segmented data library. (Closed) Base URL: https://github.com/luci/luci-go@logdog-review-streamserver
Patch Set: Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: common/chunkstream/chunkNodePool.go
diff --git a/common/chunkstream/chunkNodePool.go b/common/chunkstream/chunkNodePool.go
new file mode 100644
index 0000000000000000000000000000000000000000..0ab1f1fc44f8d5eba757cbdeef84d1e6c58b2359
--- /dev/null
+++ b/common/chunkstream/chunkNodePool.go
@@ -0,0 +1,35 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package chunkstream
+
+import (
+ "sync"
+)
+
+var chunkNodePool = sync.Pool{
+ New: func() interface{} {
+ return &chunkNode{}
+ },
+}
+
+func newChunkNode(c Chunk) *chunkNode {
+ n := chunkNodePool.Get().(*chunkNode)
+ n.Chunk = c
+ return n
+}
+
+// chunkNode wraps a Chunk interface in a linked-list node.
+type chunkNode struct {
+ Chunk
+
+ next *chunkNode
+}
+
+func (n *chunkNode) release() {
+ n.Chunk.Release()
+ n.Chunk = nil
+ n.next = nil
+ chunkNodePool.Put(n)
+}

Powered by Google App Engine
This is Rietveld 408576698