func (b *bitState) reset(prog *syntax.Prog, end int, ncap int) {
	b.end = end
	if cap(b.jobs) == 0 {
		b.jobs = make([]job, 0, 256)
	} else {
		b.jobs = b.jobs[:0]
	}
	visitedSize := (len(prog.Inst)*(end+1) + visitedBits - 1) / visitedBits
	if cap(b.visited) < visitedSize {
		b.visited = make([]uint32, visitedSize, maxBacktrackVector/visitedBits)
	} else {
		b.visited = b.visited[:visitedSize]
		for i := range b.visited {
			b.visited[i] = 0
		}
	}
	if cap(b.cap) < ncap {
		b.cap = make([]int, ncap)
	} else {
		b.cap = b.cap[:ncap]
	}
	for i := range b.cap {
		b.cap[i] = -1
	}
	if cap(b.matchcap) < ncap {
		b.matchcap = make([]int, ncap)
	} else {
		b.matchcap = b.matchcap[:ncap]
	}
	for i := range b.matchcap {
		b.matchcap[i] = -1
	}
}
reset resets the state of the backtracker.
end is the end position in the input.
ncap is the number of captures.
package binaryregexp
import (
	"sync"
	"rsc.io/binaryregexp/syntax"
)
type job struct {
	pc  uint32
	arg bool
	pos int
}
const (
	visitedBits        = 32
	maxBacktrackProg   = 500         
	maxBacktrackVector = 256 * 1024  
)
type bitState struct {
	end      int
	cap      []int
	matchcap []int
	jobs     []job
	visited  []uint32
	inputs inputs
}
var bitStatePool sync.Pool
func newBitState() *bitState {
	b, ok := bitStatePool.Get().(*bitState)
	if !ok {
		b = new(bitState)
	}
	return b
}
func freeBitState(b *bitState) {
	b.inputs.clear()
	bitStatePool.Put(b)
}
func maxBitStateLen(prog *syntax.Prog) int {
	if !shouldBacktrack(prog) {
		return 0
	}
	return maxBacktrackVector / len(prog.Inst)
}
func shouldBacktrack(prog *syntax.Prog) bool {
	return len(prog.Inst) <= maxBacktrackProg
}