From 3c8a0c4169f4bd95ec839f0abf97137e48964803 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Tue, 27 Jul 2021 19:07:10 +0200 Subject: [PATCH] Shift to go-toml v2 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A benchark building a site with 200 pages with TOML front matter: ```bash name old time/op new time/op delta SiteNew/Regular_TOML_front_matter-16 48.5ms ± 1% 47.1ms ± 1% -2.85% (p=0.029 n=4+4) name old alloc/op new alloc/op delta SiteNew/Regular_TOML_front_matter-16 16.9MB ± 0% 16.7MB ± 0% -1.56% (p=0.029 n=4+4) name old allocs/op new allocs/op delta SiteNew/Regular_TOML_front_matter-16 302k ± 0% 296k ± 0% -2.20% (p=0.029 n=4+4) ``` Note that the front matter unmarshaling is only a small part of building a site, so the above is very good. Fixes #8801 --- go.mod | 2 +- go.sum | 5 ++++- parser/frontmatter.go | 2 +- parser/frontmatter_test.go | 4 ++-- parser/metadecoders/decoder.go | 2 +- 5 files changed, 9 insertions(+), 6 deletions(-) diff --git a/go.mod b/go.mod index 3d0919af780..8819ddf33fa 100644 --- a/go.mod +++ b/go.mod @@ -2,7 +2,6 @@ module github.com/gohugoio/hugo require ( github.com/BurntSushi/locker v0.0.0-20171006230638-a6e239ea1c69 - github.com/BurntSushi/toml v0.3.1 github.com/PuerkitoBio/purell v1.1.1 github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect github.com/alecthomas/chroma v0.9.2 @@ -45,6 +44,7 @@ require ( github.com/niklasfasching/go-org v1.5.0 github.com/olekukonko/tablewriter v0.0.5 github.com/pelletier/go-toml v1.9.3 + github.com/pelletier/go-toml/v2 v2.0.0-beta.3 github.com/pkg/errors v0.9.1 github.com/rogpeppe/go-internal v1.8.0 github.com/russross/blackfriday v1.5.3-0.20200218234912-41c5fccfd6f6 diff --git a/go.sum b/go.sum index 0350e4e1dfd..76b8a80229a 100644 --- a/go.sum +++ b/go.sum @@ -433,6 +433,8 @@ github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6 github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc= github.com/pelletier/go-toml v1.9.3 h1:zeC5b1GviRUyKYd6OJPvBU/mcVDVoL1OhT17FCt5dSQ= github.com/pelletier/go-toml v1.9.3/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c= +github.com/pelletier/go-toml/v2 v2.0.0-beta.3 h1:PNCTU4naEJ8mKal97P3A2qDU74QRQGlv4FXiL1XDqi4= +github.com/pelletier/go-toml/v2 v2.0.0-beta.3/go.mod h1:aNseLYu/uKskg0zpr/kbr2z8yGuWtotWf/0BpGIAL2Y= github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= @@ -490,8 +492,9 @@ github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UV github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.7.1-0.20210427113832-6241f9ab9942 h1:t0lM6y/M5IiUZyvbBTcngso8SZEZICH7is9B6g/obVU= +github.com/stretchr/testify v1.7.1-0.20210427113832-6241f9ab9942/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/subosito/gotenv v1.2.0 h1:Slr1R9HxAlEKefgq5jn9U+DnETlIUa6HfgEzj0g5d7s= github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw= github.com/tdewolff/minify/v2 v2.9.19 h1:QdCQhIqCeBnSWU/4e0nJ8QJeQUNO5CC7jrH3xwETkVI= diff --git a/parser/frontmatter.go b/parser/frontmatter.go index 4965d3fe889..e7492745e46 100644 --- a/parser/frontmatter.go +++ b/parser/frontmatter.go @@ -20,7 +20,7 @@ import ( "github.com/gohugoio/hugo/parser/metadecoders" - "github.com/BurntSushi/toml" + toml "github.com/pelletier/go-toml/v2" yaml "gopkg.in/yaml.v2" ) diff --git a/parser/frontmatter_test.go b/parser/frontmatter_test.go index 9d9b7c3b867..dfbc695d8ff 100644 --- a/parser/frontmatter_test.go +++ b/parser/frontmatter_test.go @@ -31,9 +31,9 @@ func TestInterfaceToConfig(t *testing.T) { // TOML {map[string]interface{}{}, metadecoders.TOML, nil, false}, { - map[string]interface{}{"title": "test 1"}, + map[string]interface{}{"title": "test' 1"}, metadecoders.TOML, - []byte("title = \"test 1\"\n"), + []byte("title = \"test' 1\"\n"), false, }, diff --git a/parser/metadecoders/decoder.go b/parser/metadecoders/decoder.go index 131d6f39b06..168c130ed90 100644 --- a/parser/metadecoders/decoder.go +++ b/parser/metadecoders/decoder.go @@ -24,7 +24,7 @@ import ( "github.com/gohugoio/hugo/common/herrors" "github.com/niklasfasching/go-org/org" - "github.com/BurntSushi/toml" + toml "github.com/pelletier/go-toml/v2" "github.com/pkg/errors" "github.com/spf13/afero" "github.com/spf13/cast"