all: Temporarily revert to BurntSushi for TOML front matter handling

We still have go-toml as a transitive dependency, and it is the way to go eventually, but we care about speed, so let us wait that one out.

Note that the issue this fixes is about taxonomies, but I guess this is a general issue for sites with many pages that uses TOML as front matter.

```
benchmark                              old ns/op     new ns/op     delta
BenchmarkFrontmatterTags/TOML:1-4      23206         8543          -63.19%
BenchmarkFrontmatterTags/TOML:11-4     80117         18495         -76.92%
BenchmarkFrontmatterTags/TOML:21-4     140676        28727         -79.58%

benchmark                              old allocs     new allocs     delta
BenchmarkFrontmatterTags/TOML:1-4      173            60             -65.32%
BenchmarkFrontmatterTags/TOML:11-4     625            138            -77.92%
BenchmarkFrontmatterTags/TOML:21-4     1106           210            -81.01%

benchmark                              old bytes     new bytes     delta
BenchmarkFrontmatterTags/TOML:1-4      9231          2912          -68.45%
BenchmarkFrontmatterTags/TOML:11-4     19808         5184          -73.83%
BenchmarkFrontmatterTags/TOML:21-4     31200         7536          -75.85%
```

See #3541
Updates #3464
This commit is contained in:
Bjørn Erik Pedersen 2017-05-31 13:10:46 +03:00
parent 3d9c4f513b
commit 0907a5c1c2
3 changed files with 9 additions and 24 deletions

View file

@ -355,7 +355,7 @@ func newContentPathSection(path string) (string, string) {
} }
func createConfig(fs *hugofs.Fs, inpath string, kind string) (err error) { func createConfig(fs *hugofs.Fs, inpath string, kind string) (err error) {
in := map[string]interface{}{ in := map[string]string{
"baseURL": "http://example.org/", "baseURL": "http://example.org/",
"title": "My New Hugo Site", "title": "My New Hugo Site",
"languageCode": "en-us", "languageCode": "en-us",

View file

@ -25,7 +25,7 @@ import (
"path/filepath" "path/filepath"
toml "github.com/pelletier/go-toml" "github.com/BurntSushi/toml"
"github.com/spf13/hugo/source" "github.com/spf13/hugo/source"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
@ -634,12 +634,7 @@ func setupMenuTests(t *testing.T, pageSources []source.ByteSource, configKeyValu
} }
func tomlToMap(s string) (map[string]interface{}, error) { func tomlToMap(s string) (map[string]interface{}, error) {
tree, err := toml.Load(s) var data = make(map[string]interface{})
_, err := toml.Decode(s, &data)
if err != nil { return data, err
return nil, err
}
return tree.ToMap(), nil
} }

View file

@ -20,8 +20,8 @@ import (
"io" "io"
"strings" "strings"
"github.com/BurntSushi/toml"
"github.com/chaseadamsio/goorgeous" "github.com/chaseadamsio/goorgeous"
toml "github.com/pelletier/go-toml"
"gopkg.in/yaml.v2" "gopkg.in/yaml.v2"
) )
@ -52,13 +52,7 @@ func InterfaceToConfig(in interface{}, mark rune, w io.Writer) error {
return err return err
case rune(TOMLLead[0]): case rune(TOMLLead[0]):
tree, err := toml.TreeFromMap(in.(map[string]interface{})) return toml.NewEncoder(w).Encode(in)
if err != nil {
return err
}
_, err = tree.WriteTo(w)
return err
case rune(JSONLead[0]): case rune(JSONLead[0]):
b, err := json.MarshalIndent(in, "", " ") b, err := json.MarshalIndent(in, "", " ")
if err != nil { if err != nil {
@ -176,14 +170,10 @@ func HandleTOMLMetaData(datum []byte) (interface{}, error) {
m := map[string]interface{}{} m := map[string]interface{}{}
datum = removeTOMLIdentifier(datum) datum = removeTOMLIdentifier(datum)
tree, err := toml.LoadReader(bytes.NewReader(datum)) _, err := toml.Decode(string(datum), &m)
if err != nil {
return m, err return m, err
}
m = tree.ToMap()
return m, nil
} }
// removeTOMLIdentifier removes, if necessary, beginning and ending TOML // removeTOMLIdentifier removes, if necessary, beginning and ending TOML