MCPcopy Index your code
hub / github.com/pquerna/ffjson / Pool

Function Pool

fflib/v1/buffer_pool.go:67–89  ·  view source on GitHub ↗

Send a buffer to the Pool to reuse for other instances. You may no longer utilize the content of the buffer, since it may be used by other goroutines.

(b []byte)

Source from the content-addressed store, hash-verified

65// You may no longer utilize the content of the buffer, since it may be used
66// by other goroutines.
67func Pool(b []byte) {
68 if b == nil {
69 return
70 }
71 c := cap(b)
72
73 // Our smallest buffer is 64 bytes, so we discard smaller buffers.
74 if c < 64 {
75 return
76 }
77
78 // We need to put the incoming buffer into the NEXT buffer,
79 // since a buffer guarantees AT LEAST the number of bytes available
80 // that is the top of this buffer.
81 // That is the reason for dividing the cap by 2, so it gets into the NEXT bucket.
82 // We add 2 to avoid rounding down if size is exactly power of 2.
83 pn := poolNum((c + 2) >> 1)
84 if pn != -1 {
85 pools[pn].Put(b[0:0])
86 }
87 // if we didn't have a slot for this []byte, we just drop it and let the GC
88 // take care of it.
89}
90
91// makeSlice allocates a slice of size n -- it will attempt to use a pool'ed
92// instance whenever possible.

Callers 3

growMethod · 0.70
ReadFromMethod · 0.70
FormatBits2Function · 0.70

Calls 1

poolNumFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…