Skip to content

Commit 9b890cf

Browse files
authored
go.mod: bump minimum and language to 1.21 (#949)
* go.mod: bump minimum and language to 1.21 CI only tests Go 1.21 and 1.22, and older versions of Go are no longer getting any bug or security fixes, so advertise that we only support Go 1.21 or later via go.mod. While here, ensure the module is tidy and resolve deprecation warnings, and remove now-unnecessary Go version build tags. * replace sort.Slice with slices.SortFunc The latter is more efficient, and allocates less, since sort.Slice needs to go through sort.Interface which causes allocations. goos: linux goarch: amd64 pkg: github.com/pelletier/go-toml/v2/benchmark cpu: AMD Ryzen 7 PRO 5850U with Radeon Graphics │ old │ new │ │ sec/op │ sec/op vs base │ Marshal/HugoFrontMatter-8 7.612µ ± 1% 6.730µ ± 1% -11.59% (p=0.002 n=6) │ old │ new │ │ B/s │ B/s vs base │ Marshal/HugoFrontMatter-8 65.52Mi ± 1% 74.11Mi ± 1% +13.11% (p=0.002 n=6) │ old │ new │ │ B/op │ B/op vs base │ Marshal/HugoFrontMatter-8 5.672Ki ± 0% 5.266Ki ± 0% -7.16% (p=0.002 n=6) │ old │ new │ │ allocs/op │ allocs/op vs base │ Marshal/HugoFrontMatter-8 85.00 ± 0% 73.00 ± 0% -14.12% (p=0.002 n=6)
1 parent a3d5a0b commit 9b890cf

File tree

6 files changed

+14
-24
lines changed

6 files changed

+14
-24
lines changed

fuzz_test.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
//go:build go1.18 || go1.19 || go1.20 || go1.21 || go1.22
2-
// +build go1.18 go1.19 go1.20 go1.21 go1.22
3-
41
package toml_test
52

63
import (

go.mod

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
module github.com/pelletier/go-toml/v2
22

3-
go 1.16
3+
go 1.21
44

55
require github.com/stretchr/testify v1.9.0
6+
7+
require (
8+
github.com/davecgh/go-spew v1.1.1 // indirect
9+
github.com/pmezard/go-difflib v1.0.0 // indirect
10+
gopkg.in/yaml.v3 v3.0.1 // indirect
11+
)

go.sum

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,10 @@
1-
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
21
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
32
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
43
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
54
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
6-
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
7-
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
8-
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
9-
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
10-
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
11-
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
12-
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
135
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
146
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
157
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
168
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
17-
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
189
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
1910
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

marshaler.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"io"
99
"math"
1010
"reflect"
11-
"sort"
11+
"slices"
1212
"strconv"
1313
"strings"
1414
"time"
@@ -280,7 +280,7 @@ func (enc *Encoder) encode(b []byte, ctx encoderCtx, v reflect.Value) ([]byte, e
280280
}
281281

282282
hasTextMarshaler := v.Type().Implements(textMarshalerType)
283-
if hasTextMarshaler || (v.CanAddr() && reflect.PtrTo(v.Type()).Implements(textMarshalerType)) {
283+
if hasTextMarshaler || (v.CanAddr() && reflect.PointerTo(v.Type()).Implements(textMarshalerType)) {
284284
if !hasTextMarshaler {
285285
v = v.Addr()
286286
}
@@ -668,8 +668,8 @@ func (enc *Encoder) encodeMap(b []byte, ctx encoderCtx, v reflect.Value) ([]byte
668668
}
669669

670670
func sortEntriesByKey(e []entry) {
671-
sort.Slice(e, func(i, j int) bool {
672-
return e[i].Key < e[j].Key
671+
slices.SortFunc(e, func(a, b entry) int {
672+
return strings.Compare(a.Key, b.Key)
673673
})
674674
}
675675

@@ -951,7 +951,7 @@ func willConvertToTable(ctx encoderCtx, v reflect.Value) bool {
951951
if !v.IsValid() {
952952
return false
953953
}
954-
if v.Type() == timeType || v.Type().Implements(textMarshalerType) || (v.Kind() != reflect.Ptr && v.CanAddr() && reflect.PtrTo(v.Type()).Implements(textMarshalerType)) {
954+
if v.Type() == timeType || v.Type().Implements(textMarshalerType) || (v.Kind() != reflect.Ptr && v.CanAddr() && reflect.PointerTo(v.Type()).Implements(textMarshalerType)) {
955955
return false
956956
}
957957

ossfuzz/fuzz.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
//go:build go1.18 || go1.19 || go1.20 || go1.21 || go1.22
2-
// +build go1.18 go1.19 go1.20 go1.21 go1.22
3-
41
package ossfuzz
52

63
import (

unmarshaler.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"errors"
66
"fmt"
77
"io"
8-
"io/ioutil"
98
"math"
109
"reflect"
1110
"strings"
@@ -117,7 +116,7 @@ func (d *Decoder) EnableUnmarshalerInterface() *Decoder {
117116
// Inline Table -> same as Table
118117
// Array of Tables -> same as Array and Table
119118
func (d *Decoder) Decode(v interface{}) error {
120-
b, err := ioutil.ReadAll(d.r)
119+
b, err := io.ReadAll(d.r)
121120
if err != nil {
122121
return fmt.Errorf("toml: %w", err)
123122
}
@@ -1078,7 +1077,7 @@ func (d *decoder) keyFromData(keyType reflect.Type, data []byte) (reflect.Value,
10781077
}
10791078
return mk, nil
10801079

1081-
case reflect.PtrTo(keyType).Implements(textUnmarshalerType):
1080+
case reflect.PointerTo(keyType).Implements(textUnmarshalerType):
10821081
mk := reflect.New(keyType)
10831082
if err := mk.Interface().(encoding.TextUnmarshaler).UnmarshalText(data); err != nil {
10841083
return reflect.Value{}, fmt.Errorf("toml: error unmarshalling key type %s from text: %w", stringType, err)

0 commit comments

Comments
 (0)