MCPcopy Index your code
hub / github.com/allegro/bigcache / allocateAdditionalMemory

Method allocateAdditionalMemory

queue/bytes_queue.go:108–140  ·  view source on GitHub ↗
(minimum int)

Source from the content-addressed store, hash-verified

106}
107
108func (q *BytesQueue) allocateAdditionalMemory(minimum int) {
109 start := time.Now()
110 if q.capacity < minimum {
111 q.capacity += minimum
112 }
113 q.capacity = q.capacity * 2
114 if q.capacity > q.maxCapacity && q.maxCapacity > 0 {
115 q.capacity = q.maxCapacity
116 }
117
118 oldArray := q.array
119 q.array = make([]byte, q.capacity)
120
121 if leftMarginIndex != q.rightMargin {
122 copy(q.array, oldArray[:q.rightMargin])
123
124 if q.tail <= q.head {
125 if q.tail != q.head {
126 // created slice is slightly larger then need but this is fine after only the needed bytes are copied
127 q.push(make([]byte, q.head-q.tail), q.head-q.tail)
128 }
129
130 q.head = leftMarginIndex
131 q.tail = q.rightMargin
132 }
133 }
134
135 q.full = false
136
137 if q.verbose {
138 log.Printf("Allocated new queue in %s; Capacity: %d \n", time.Since(start), q.capacity)
139 }
140}
141
142func (q *BytesQueue) push(data []byte, len int) {
143 headerEntrySize := binary.PutUvarint(q.headerBuffer, uint64(len))

Callers 1

PushMethod · 0.95

Calls 2

pushMethod · 0.95
PrintfMethod · 0.65

Tested by

no test coverage detected