<commit_before>// +build !appengine

package generic

import (
	"reflect"
	"unsafe"
)

type handle uintptr

func indexer(t reflect.Type) indexFunc {
	size := t.Size()
	return func(v handle, i int) handle {
		header := (*reflect.SliceHeader)(unsafe.Pointer(&v))
		return handle(header.Data + uintptr(i)*size)
	}
}

func swapper(t reflect.Type) swapFunc {
	size := t.Size()
	return func(v handle, i, j int) {
		header := (*reflect.SliceHeader)(unsafe.Pointer(&v))
		tmp := make([]byte, size)
		var si []byte
		hi := (*reflect.SliceHeader)(unsafe.Pointer(&si))
		hi.Len = int(size)
		hi.Data = header.Data + uintptr(i)*size
		var sj []byte
		hj := (*reflect.SliceHeader)(unsafe.Pointer(&sj))
		hj.Len = int(size)
		hj.Data = header.Data + uintptr(j)*size
		copy(tmp, sj)
		copy(sj, si)
		copy(si, tmp)
	}
}

func fieldValueFunc(field reflect.StructField, depth int) mapFunc {
	offset := field.Offset
	switch depth {
	case 0:
		return func(v handle) handle {
			return handle(uintptr(v) + offset)<commit_msg>Reuse the same buffer in the swapper function<commit_after>// +build !appengine

package generic

import (
	"reflect"
	"unsafe"
)

type handle uintptr

func indexer(t reflect.Type) indexFunc {
	size := t.Size()
	return func(v handle, i int) handle {
		header := (*reflect.SliceHeader)(unsafe.Pointer(&v))
		return handle(header.Data + uintptr(i)*size)
	}
}

func swapper(t reflect.Type) swapFunc {
	size := t.Size()
	tmp := make([]byte, size)
	return func(v handle, i, j int) {
		header := (*reflect.SliceHeader)(unsafe.Pointer(&v))
		var si []byte
		hi := (*reflect.SliceHeader)(unsafe.Pointer(&si))
		hi.Len = int(size)
		hi.Data = header.Data + uintptr(i)*size
		var sj []byte
		hj := (*reflect.SliceHeader)(unsafe.Pointer(&sj))
		hj.Len = int(size)
		hj.Data = header.Data + uintptr(j)*size
		copy(tmp, sj)
		copy(sj, si)
		copy(si, tmp)
	}
}

func fieldValueFunc(field reflect.StructField, depth int) mapFunc {
	offset := field.Offset
	switch depth {
	case 0:
		return func(v handle) handle {
			return handle(uintptr(v) + offset)
{'fraction_non_alphanumeric': 0.15595880333496812, 'fraction_numerical': 0.000980872976949485, 'mean_word_length': 4.190839694656488, 'pattern_counts': {'":': 0, '<': 3, '<?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': '6411364', 'n_tokens_mistral': 783, 'n_tokens_neox': 726, 'n_words': 186}