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

Unified Diff: common/chunkstream/chunkNode.go

Issue 1413923013: Add `chunk` segmented data library. (Closed) Base URL: https://github.com/luci/luci-go@logdog-review-streamserver
Patch Set: Use errors in pacnic. 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
« no previous file with comments | « common/chunkstream/chunk.go ('k') | common/chunkstream/chunk_test.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: common/chunkstream/chunkNode.go
diff --git a/common/chunkstream/chunkNode.go b/common/chunkstream/chunkNode.go
new file mode 100644
index 0000000000000000000000000000000000000000..ce54cc9154d7c1f56eb806e77b009d4ea43b2f04
--- /dev/null
+++ b/common/chunkstream/chunkNode.go
@@ -0,0 +1,39 @@
+// 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)
+}
+
+func (n *chunkNode) length() int {
+ return len(n.Bytes())
+}
« no previous file with comments | « common/chunkstream/chunk.go ('k') | common/chunkstream/chunk_test.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698