<commit_before>/**********************************************************\
|                                                          |
|                          hprose                          |
|                                                          |
| Official WebSite: http://www.hprose.com/                 |
|                   http://www.hprose.org/                 |
|                                                          |
\**********************************************************/
/**********************************************************\
 *                                                        *
 * io/byte_pool.go                                        *
 *                                                        *
 * byte pool for Go.                                      *
 *                                                        *
 * LastModified: Sep 1, 2016                              *
 * Author: <NAME> <<EMAIL>>                  *
 *                                                        *
\**********************************************************/

package io

import (
	"sync"
	"time"
)

const (
	poolNum = 20
	maxSize = 1 << (poolNum + 5)
)

type pool struct {
	list   [][]byte
	locker sync.Mutex
}

var bytePool = struct {
	pools [poolNum]pool
	timer *time.Timer
	d     time.Duration
}{}

func init() {
	bytePool.d = time.Second * 4
	if bytePool.d > 0 {
		bytePool.timer = time.AfterFunc(bytePool.d, func() {
			drain()
			bytePool.timer.Reset(bytePool.d)
		})
	}
}

func drain() {
	n := len(bytePool.pools)
	for i := 0; i < n; i++ {
		p := &bytePool.pools[i]
		p.locker.Lock()
		p.list = p.list[:len(p.list)>>1]
		p.locker.Unlock()
	}
}

// Alloc a []byte from pool.
func Alloc(size int) []byte {<commit_msg>Fixed drain<commit_after>/**********************************************************\
|                                                          |
|                          hprose                          |
|                                                          |
| Official WebSite: http://www.hprose.com/                 |
|                   http://www.hprose.org/                 |
|                                                          |
\**********************************************************/
/**********************************************************\
 *                                                        *
 * io/byte_pool.go                                        *
 *                                                        *
 * byte pool for Go.                                      *
 *                                                        *
 * LastModified: Sep 1, 2016                              *
 * Author: <NAME> <<EMAIL>>                  *
 *                                                        *
\**********************************************************/

package io

import (
	"sync"
	"time"
)

const (
	poolNum = 20
	maxSize = 1 << (poolNum + 5)
)

type pool struct {
	list   [][]byte
	locker sync.Mutex
}

var bytePool = struct {
	pools [poolNum]pool
	timer *time.Timer
	d     time.Duration
}{}

func init() {
	bytePool.d = time.Second << 2
	if bytePool.d > 0 {
		bytePool.timer = time.AfterFunc(bytePool.d, func() {
			drain()
			bytePool.timer.Reset(bytePool.d)
		})
	}
}

func drain() {
	n := len(bytePool.pools)
	for i := 0; i < n; i++ {
		p := &bytePool.pools[i]
		p.locker.Lock()
		l := len(p.list)
		for j := l - 1; j >= l>>1; j-- {
			p.list[j] = nil
		}
		p.list = p.list[:l>>1]
		p.locker.Unlock()
	}
}

// Alloc a []byte from pool.
func Alloc(size int) []byte {
{'fraction_non_alphanumeric': 0.2353269983230855, 'fraction_numerical': 0.007825600894354388, 'mean_word_length': 1.0393162393162394, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 18, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 32, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5237737', 'n_tokens_mistral': 954, 'n_tokens_neox': 883, 'n_words': 180}