<commit_before>package objconv

import (
	"encoding"
	"fmt"
	"io"
	"reflect"
	"time"
	"unsafe"
)

// An Encoder implements the high-level encoding algorithm that inspect encoded
// values and drive the use of an Emitter to create a serialized representation
// of the data.
//
// Instances of Encoder are not safe for use by multiple goroutines.
type Encoder struct {
	Emitter     Emitter // the emitter used by this encoder
	SortMapKeys bool    // whether map keys should be sorted
	key         bool
}

// NewEncoder returns a new encoder that outputs values to e.
//
// Encoders created by this function use the default encoder configuration,
// which is equivalent to using a zero-value EncoderConfig with only the Emitter
// field set.
//
// The function panics if e is nil.
func NewEncoder(e Emitter) *Encoder {
	if e == nil {
		panic("objconv: the emitter is nil")
	}
	return &Encoder{Emitter: e}
}

// Encode encodes the generic value v.
func (e Encoder) Encode(v interface{}) (err error) {
	if err = e.encodeMapValueMaybe(); err != nil {
		return
	}

	// This type switch optimizes encoding of common value types, it prevents
	// the use of reflection to identify the type of the value, which saves a
	// dynamic memory allocation.
	switch x := v.(type) {
	case nil:
		return e.Emitter.EmitNil()

	case bool:
		return e.Emitter.EmitBool(x)

	case int:
		return e.Emitter.EmitInt(int64(x), int(8*unsafe.Sizeof(0)))

	case int8:
		return e.Emitter.EmitInt(int64(x), 8)

	case int16:
		return e.Emitter.EmitInt(int64(x), 16)

	case int32:
		return e.Emitter.EmitInt(int64(x), 32)

	case int64:
		return e.Emitter.EmitInt(x, 64)

	case uint8:
		return e.Emitter.EmitUint(uint64(x), 8)

	case uint16:
		return e.Emitter.EmitUint(uint64(x), 16)

	case uint32:
		return e.Emitter.EmitUint(uint64(x), 32)

	case uint64:
		return e.Emitter.EmitUint(x, 64)

	case string:
		return e.Emitter.EmitString(x)

	case []byte:
		return e.Emitter.EmitBytes(x)

	case time.Time:
		return e.Emitter.EmitTime(x)

	case time.Duration:
		return e.Emitter.EmitDuration(x)

	case error:
		return e.Emitter.EmitError(x)

	case []string:
		return e.encodeSliceOfString(x)

	case []interface{}:
		return e.encodeSliceOfInterface(x)

	case map[string]string:
		return e.encodeMapStringString(x)

	case map[string]interface{}:
		return e.encodeMapStringInterface(x)

	case map[interface{}]interface{}:
		return e.encodeMapInterfaceInterface(x)

		// Also checks for pointer types so the program can use this as a way
		// to avoid the dynamic memory allocation done by runtime.convT2E for
		// converting non-pointer types to empty interfaces.
	case *bool:
		return e.Emitter.EmitBool(*x)

	case *int:
		return e.Emitter.EmitInt(int64(*x), int(8*unsafe.Sizeof(0)))

	case *int8:
		return e.Emitter.EmitInt(int64(*x), 8)

	case *int16:
		return e.Emitter.EmitInt(int64(*x), 16)

	case *int32:
		return e.Emitter.EmitInt(int64(*x), 32)

	case *int64:
		return e.Emitter.EmitInt(*x, 64)

	case *uint8:
		return e.Emitter.EmitUint(uint64(*x), 8)

	case *uint16:
		return e.Emitter.EmitUint(uint64(*x), 16)

	case *uint32:
		return e.Emitter.EmitUint(uint64(*x), 32)

	case *uint64:
		return e.Emitter.EmitUint(*x, 64)

	case *string:
		return e.Emitter.EmitString(*x)

	case *[]byte:
		return e.Emitter.EmitBytes(*x)

	case *time.Time:
		return e.Emitter.EmitTime(*x)

	case *time.Duration:
		return e.Emitter.EmitDuration(*x)

	case *error:
		return e.Emitter.EmitError(*x)

	case *[]string:
		return e.encodeSliceOfString(*x)<commit_msg>cleanup<commit_after>package objconv

import (
	"encoding"
	"fmt"
	"io"
	"reflect"
	"time"
	"unsafe"
)

// An Encoder implements the high-level encoding algorithm that inspect encoded
// values and drive the use of an Emitter to create a serialized representation
// of the data.
//
// Instances of Encoder are not safe for use by multiple goroutines.
type Encoder struct {
	Emitter     Emitter // the emitter used by this encoder
	SortMapKeys bool    // whether map keys should be sorted
	key         bool
}

// NewEncoder returns a new encoder that outputs values to e.
//
// Encoders created by this function use the default encoder configuration,
// which is equivalent to using a zero-value EncoderConfig with only the Emitter
// field set.
//
// The function panics if e is nil.
func NewEncoder(e Emitter) *Encoder {
	if e == nil {
		panic("objconv: the emitter is nil")
	}
	return &Encoder{Emitter: e}
}

// Encode encodes the generic value v.
func (e Encoder) Encode(v interface{}) (err error) {
	if err = e.encodeMapValueMaybe(); err != nil {
		return
	}

	// This type switch optimizes encoding of common value types, it prevents
	// the use of reflection to identify the type of the value, which saves a
	// dynamic memory allocation.
	switch x := v.(type) {
	case nil:
		return e.Emitter.EmitNil()

	case bool:
		return e.Emitter.EmitBool(x)

	case int:
		return e.Emitter.EmitInt(int64(x), int(8*unsafe.Sizeof(0)))

	case int8:
		return e.Emitter.EmitInt(int64(x), 8)

	case int16:
		return e.Emitter.EmitInt(int64(x), 16)

	case int32:
		return e.Emitter.EmitInt(int64(x), 32)

	case int64:
		return e.Emitter.EmitInt(x, 64)

	case uint8:
		return e.Emitter.EmitUint(uint64(x), 8)

	case uint16:
		return e.Emitter.EmitUint(uint64(x), 16)

	case uint32:
		return e.Emitter.EmitUint(uint64(x), 32)

	case uint64:
		return e.Emitter.EmitUint(x, 64)

	case string:
		return e.Emitter.EmitString(x)

	case []byte:
		return e.Emitter.EmitBytes(x)

	case time.Time:
		return e.Emitter.EmitTime(x)

	case time.Duration:
		return e.Emitter.EmitDuration(x)

	case []string:
		return e.encodeSliceOfString(x)

	case []interface{}:
		return e.encodeSliceOfInterface(x)

	case map[string]string:
		return e.encodeMapStringString(x)

	case map[string]interface{}:
		return e.encodeMapStringInterface(x)

	case map[interface{}]interface{}:
		return e.encodeMapInterfaceInterface(x)

		// Also checks for pointer types so the program can use this as a way
		// to avoid the dynamic memory allocation done by runtime.convT2E for
		// converting non-pointer types to empty interfaces.
	case *bool:
		return e.Emitter.EmitBool(*x)

	case *int:
		return e.Emitter.EmitInt(int64(*x), int(8*unsafe.Sizeof(0)))

	case *int8:
		return e.Emitter.EmitInt(int64(*x), 8)

	case *int16:
		return e.Emitter.EmitInt(int64(*x), 16)

	case *int32:
		return e.Emitter.EmitInt(int64(*x), 32)

	case *int64:
		return e.Emitter.EmitInt(*x, 64)

	case *uint8:
		return e.Emitter.EmitUint(uint64(*x), 8)

	case *uint16:
		return e.Emitter.EmitUint(uint64(*x), 16)

	case *uint32:
		return e.Emitter.EmitUint(uint64(*x), 32)

	case *uint64:
		return e.Emitter.EmitUint(*x, 64)

	case *string:
		return e.Emitter.EmitString(*x)

	case *[]byte:
		return e.Emitter.EmitBytes(*x)

	case *time.Time:
		return e.Emitter.EmitTime(*x)

	case *time.Duration:
		return e.Emitter.EmitDuration(*x)

	case *[]string:
		return e.encodeSliceOfString(*x)
{'fraction_non_alphanumeric': 0.11810568870921166, 'fraction_numerical': 0.025700259890268553, 'mean_word_length': 3.8070784177654406, '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': '1710777', 'n_tokens_mistral': 2646, 'n_tokens_neox': 2474, 'n_words': 729}