<commit_before>package main

import (
	"compress/gzip"
	"io"
	"io/ioutil"
	"sync"
)

type gzipPool struct {
	mutex sync.Mutex
	top   *gzipPoolEntry
}

type gzipPoolEntry struct {
	gz   *gzip.Writer
	next *gzipPoolEntry
}

func newGzipPool(n int) *gzipPool {
	pool := new(gzipPool)

	for i := 0; i < n; i++ {
		pool.grow()
	}

	return pool
}

func (p *gzipPool) grow() {
	gz, err := gzip.NewWriterLevel(ioutil.Discard, conf.GZipCompression)
	if err != nil {
		logFatal("Can't init GZip compression: %s", err)
	}

	p.top = &gzipPoolEntry{
		gz:   gz,
		next: p.top,
	}
}

func (p *gzipPool) Get(w io.Writer) *gzip.Writer {
	p.mutex.Lock()
	defer p.mutex.Unlock()

	if p.top == nil {
		p.grow()
	}

	gz := p.top.gz
	gz.Reset(w)

	p.top = p.top.next

	return gz
}

func (p *gzipPool) Put(gz *gzip.Writer) {
	p.mutex.Lock()
	defer p.mutex.Unlock()

	p.top = &gzipPoolEntry{gz: gz, next: p.top}
}<commit_msg>Reset gzip encoder on put to pool<commit_after>package main

import (
	"compress/gzip"
	"io"
	"io/ioutil"
	"sync"
)

type gzipPool struct {
	mutex sync.Mutex
	top   *gzipPoolEntry
}

type gzipPoolEntry struct {
	gz   *gzip.Writer
	next *gzipPoolEntry
}

func newGzipPool(n int) *gzipPool {
	pool := new(gzipPool)

	for i := 0; i < n; i++ {
		pool.grow()
	}

	return pool
}

func (p *gzipPool) grow() {
	gz, err := gzip.NewWriterLevel(ioutil.Discard, conf.GZipCompression)
	if err != nil {
		logFatal("Can't init GZip compression: %s", err)
	}

	p.top = &gzipPoolEntry{
		gz:   gz,
		next: p.top,
	}
}

func (p *gzipPool) Get(w io.Writer) *gzip.Writer {
	p.mutex.Lock()
	defer p.mutex.Unlock()

	if p.top == nil {
		p.grow()
	}

	gz := p.top.gz
	gz.Reset(w)

	p.top = p.top.next

	return gz
}

func (p *gzipPool) Put(gz *gzip.Writer) {
	p.mutex.Lock()
	defer p.mutex.Unlock()

	gz.Reset(ioutil.Discard)

	p.top = &gzipPoolEntry{gz: gz, next: p.top}
}
{'fraction_non_alphanumeric': 0.15991356023770933, 'fraction_numerical': 0.0010804970286331713, 'mean_word_length': 3.2477064220183487, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6106926', 'n_tokens_mistral': 871, 'n_tokens_neox': 831, 'n_words': 191}