Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions ascii/ascii_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func BenchmarkValidPrint(b *testing.B) {
func benchmarkValidationFunction(b *testing.B, function func(string) bool) {
for _, test := range testStrings {
b.Run(limit(test), func(b *testing.B) {
for i := 0; i < b.N; i++ {
for range b.N {
_ = function(test)
}
b.SetBytes(int64(len(test)))
Expand Down Expand Up @@ -233,7 +233,7 @@ func BenchmarkEqualFold(b *testing.B) {
b.Run(limit(test), func(b *testing.B) {
other := test + "_" // not the same pointer

for i := 0; i < b.N; i++ {
for range b.N {
_ = EqualFoldString(test, other[:len(test)]) // same length
}

Expand Down
1 change: 1 addition & 0 deletions internal/runtime_reflect/map.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ func makemap(t unsafe.Pointer, cap int) unsafe.Pointer

// m escapes into the return value, but the caller of mapiterinit
// doesn't let the return value escape.
//
//go:noescape
//go:linkname mapiterinit runtime.mapiterinit
func mapiterinit(t unsafe.Pointer, m unsafe.Pointer, it *hiter)
Expand Down
46 changes: 23 additions & 23 deletions iso8601/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ func TestParse(t *testing.T) {
}

// Check ~4M YYYY-MM-DD dates in 20 byte form.
for year := 0; year <= 9999; year++ {
for month := 0; month <= 13; month++ {
for day := 0; day <= 32; day++ {
for year := range 10000 {
for month := range 14 {
for day := range 33 {
input := fmt.Sprintf("%04d-%02d-%02dT12:34:56Z", year, month, day)
expect, expectErr := time.Parse(time.RFC3339Nano, input)
actual, actualErr := Parse(input)
Expand All @@ -94,9 +94,9 @@ func TestParse(t *testing.T) {
}

// Check ~4M YYYY-MM-DD dates in 24 byte form.
for year := 0; year <= 9999; year++ {
for month := 0; month <= 13; month++ {
for day := 0; day <= 32; day++ {
for year := range 10000 {
for month := range 14 {
for day := range 33 {
input := fmt.Sprintf("%04d-%02d-%02dT12:34:56.789Z", year, month, day)
expect, expectErr := time.Parse(time.RFC3339Nano, input)
actual, actualErr := Parse(input)
Expand All @@ -110,9 +110,9 @@ func TestParse(t *testing.T) {
}

// Check ~4M YYYY-MM-DD dates in 30 byte form.
for year := 0; year <= 9999; year++ {
for month := 0; month <= 13; month++ {
for day := 0; day <= 32; day++ {
for year := range 10000 {
for month := range 14 {
for day := range 33 {
input := fmt.Sprintf("%04d-%02d-%02dT12:34:56.123456789Z", year, month, day)
expect, expectErr := time.Parse(time.RFC3339Nano, input)
actual, actualErr := Parse(input)
Expand All @@ -126,9 +126,9 @@ func TestParse(t *testing.T) {
}

// Check all ~1M HH:MM:SS times in 20 byte form.
for hour := 0; hour < 100; hour++ {
for minute := 0; minute < 100; minute++ {
for second := 0; second < 100; second++ {
for hour := range 100 {
for minute := range 100 {
for second := range 100 {
input := fmt.Sprintf("2000-01-01T%02d:%02d:%02dZ", hour, minute, second)
expect, expectErr := time.Parse(time.RFC3339Nano, input)
actual, actualErr := Parse(input)
Expand All @@ -142,9 +142,9 @@ func TestParse(t *testing.T) {
}

// Check ~1M HH:MM:SS.MMM times in 24 byte form.
for hour := 0; hour < 100; hour++ {
for minute := 0; minute < 100; minute++ {
for second := 0; second < 100; second++ {
for hour := range 100 {
for minute := range 100 {
for second := range 100 {
input := fmt.Sprintf("2000-01-01T%02d:%02d:%02d.123Z", hour, minute, second)
expect, expectErr := time.Parse(time.RFC3339Nano, input)
actual, actualErr := Parse(input)
Expand All @@ -158,9 +158,9 @@ func TestParse(t *testing.T) {
}

// Check ~1M HH:MM:SS.MMM times in 30 byte form.
for hour := 0; hour < 100; hour++ {
for minute := 0; minute < 100; minute++ {
for second := 0; second < 100; second++ {
for hour := range 100 {
for minute := range 100 {
for second := range 100 {
input := fmt.Sprintf("2000-01-01T%02d:%02d:%02d.123456789Z", hour, minute, second)
expect, expectErr := time.Parse(time.RFC3339Nano, input)
actual, actualErr := Parse(input)
Expand Down Expand Up @@ -405,31 +405,31 @@ func TestParseInvalid(t *testing.T) {
}

func BenchmarkParse(b *testing.B) {
for i := 0; i < b.N; i++ {
for range b.N {
Parse("2006-01-02T15:04:05Z")
}
}

func BenchmarkParseMilliseconds(b *testing.B) {
for i := 0; i < b.N; i++ {
for range b.N {
Parse("2006-01-02T15:04:05.123Z")
}
}

func BenchmarkParseMicroseconds(b *testing.B) {
for i := 0; i < b.N; i++ {
for range b.N {
Parse("2006-01-02T15:04:05.123456Z")
}
}

func BenchmarkParseNanoseconds(b *testing.B) {
for i := 0; i < b.N; i++ {
for range b.N {
Parse("2006-01-02T15:04:05.123456789Z")
}
}

func BenchmarkParseInvalid(b *testing.B) {
for i := 0; i < b.N; i++ {
for range b.N {
Parse("2006-01-02T15:04:05.XZ")
}
}
2 changes: 1 addition & 1 deletion iso8601/valid.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package iso8601

// ValidFlags is a bitset type used to configure the behavior of the Valid
//function.
// function.
type ValidFlags int

const (
Expand Down
8 changes: 4 additions & 4 deletions iso8601/valid_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,15 @@ func BenchmarkValidate(b *testing.B) {
}

func benchmarkValidateSuccess(b *testing.B) {
for i := 0; i < b.N; i++ {
for range b.N {
if !Valid("2018-01-01T23:42:59.123456789Z", Flexible) {
b.Fatal("not valid")
}
}
}

func benchmarkValidateFailure(b *testing.B) {
for i := 0; i < b.N; i++ {
for range b.N {
if Valid("2018-01-01T23:42:59 oops!", Flexible) {
b.Fatal("valid but should not")
}
Expand All @@ -89,15 +89,15 @@ func BenchmarkTimeParse(b *testing.B) {
}

func benchmarkTimeParseSuccess(b *testing.B) {
for i := 0; i < b.N; i++ {
for range b.N {
if _, err := time.Parse(time.RFC3339Nano, "2018-01-01T23:42:59.123456789Z"); err != nil {
b.Fatal("not valid")
}
}
}

func benchmarkTimeParseFailure(b *testing.B) {
for i := 0; i < b.N; i++ {
for range b.N {
if _, err := time.Parse(time.RFC3339Nano, "2018-01-01T23:42:59 oops!"); err == nil {
b.Fatal("valid but should not")
}
Expand Down
2 changes: 1 addition & 1 deletion json/bugs/issue11/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
)

func TestIssue11(t *testing.T) {
m := map[string]map[string]interface{}{
m := map[string]map[string]any{
"outerkey": {
"innerkey": "innervalue",
},
Expand Down
30 changes: 17 additions & 13 deletions json/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,15 @@ type decoder struct {
flags ParseFlags
}

type encodeFunc func(encoder, []byte, unsafe.Pointer) ([]byte, error)
type decodeFunc func(decoder, []byte, unsafe.Pointer) ([]byte, error)
type (
encodeFunc func(encoder, []byte, unsafe.Pointer) ([]byte, error)
decodeFunc func(decoder, []byte, unsafe.Pointer) ([]byte, error)
)

type emptyFunc func(unsafe.Pointer) bool
type sortFunc func([]reflect.Value)
type (
emptyFunc func(unsafe.Pointer) bool
sortFunc func([]reflect.Value)
)

// Eventually consistent cache mapping go types to dynamically generated
// codecs.
Expand Down Expand Up @@ -558,7 +562,7 @@ func appendStructFields(fields []structField, t reflect.Type, offset uintptr, se
names := make(map[string]struct{})
embedded := make([]embeddedField, 0, 10)

for i, n := 0, t.NumField(); i < n; i++ {
for i := range t.NumField() {
f := t.Field(i)

var (
Expand Down Expand Up @@ -706,7 +710,7 @@ func appendStructFields(fields []structField, t reflect.Type, offset uintptr, se
for _, embfield := range embedded {
subfield := *embfield.subfield

if ambiguousNames[subfield.name] > 1 && !(subfield.tag && ambiguousTags[subfield.name] == 1) {
if ambiguousNames[subfield.name] > 1 && (!subfield.tag || ambiguousTags[subfield.name] != 1) {
continue // ambiguous embedded field
}

Expand Down Expand Up @@ -1001,14 +1005,14 @@ var syntaxErrorMsgOffset = ^uintptr(0)

func init() {
t := reflect.TypeOf(SyntaxError{})
for i, n := 0, t.NumField(); i < n; i++ {
for i := range t.NumField() {
if f := t.Field(i); f.Type.Kind() == reflect.String {
syntaxErrorMsgOffset = f.Offset
}
}
}

func syntaxError(b []byte, msg string, args ...interface{}) error {
func syntaxError(b []byte, msg string, args ...any) error {
e := new(SyntaxError)
i := syntaxErrorMsgOffset
if i != ^uintptr(0) {
Expand Down Expand Up @@ -1096,15 +1100,15 @@ var (
timePtrType = reflect.PtrTo(timeType)
rawMessagePtrType = reflect.PtrTo(rawMessageType)

sliceInterfaceType = reflect.TypeOf(([]interface{})(nil))
sliceStringType = reflect.TypeOf(([]interface{})(nil))
mapStringInterfaceType = reflect.TypeOf((map[string]interface{})(nil))
sliceInterfaceType = reflect.TypeOf(([]any)(nil))
sliceStringType = reflect.TypeOf(([]any)(nil))
mapStringInterfaceType = reflect.TypeOf((map[string]any)(nil))
mapStringRawMessageType = reflect.TypeOf((map[string]RawMessage)(nil))
mapStringStringType = reflect.TypeOf((map[string]string)(nil))
mapStringStringSliceType = reflect.TypeOf((map[string][]string)(nil))
mapStringBoolType = reflect.TypeOf((map[string]bool)(nil))

interfaceType = reflect.TypeOf((*interface{})(nil)).Elem()
interfaceType = reflect.TypeOf((*any)(nil)).Elem()
jsonMarshalerType = reflect.TypeOf((*Marshaler)(nil)).Elem()
jsonUnmarshalerType = reflect.TypeOf((*Unmarshaler)(nil)).Elem()
textMarshalerType = reflect.TypeOf((*encoding.TextMarshaler)(nil)).Elem()
Expand Down Expand Up @@ -1203,7 +1207,7 @@ func fmtFrac(buf []byte, v uint64, prec int) (nw int, nv uint64) {
// Omit trailing zeros up to and including decimal point.
w := len(buf)
print := false
for i := 0; i < prec; i++ {
for range prec {
digit := v % 10
print = print || digit != 0
if print {
Expand Down
Loading