File: linePool.go

package info (click to toggle)
moor 2.10.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 27,960 kB
  • sloc: sh: 229; ansic: 12; xml: 6; makefile: 5
file content (23 lines) | stat: -rw-r--r-- 447 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
package reader

// This value affects BenchmarkReadLargeFile() performance. Validate changes
// like this:
//
//	go test -benchmem -run='^$' -bench 'BenchmarkReadLargeFile' ./internal/reader
const linePoolSize = 1000

type linePool struct {
	pool []Line
}

func (lp *linePool) create(raw []byte) *Line {
	if len(lp.pool) == 0 {
		lp.pool = make([]Line, linePoolSize)
	}

	line := &lp.pool[0]
	lp.pool = lp.pool[1:]

	line.raw = raw
	return line
}