From 76c552dcd7061c0432fc3fef74ab8308f2a28151 Mon Sep 17 00:00:00 2001 From: Kevin Burke Date: Wed, 3 May 2017 21:02:36 -0700 Subject: [PATCH] Initialize keys array to final length (#155) Previously we'd create an empty array and need to continuously resize it as we appended more entries. This way we immediately create the correct size array, and then add entries to it. --- toml.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/toml.go b/toml.go index 1ba56a1..75e43ab 100644 --- a/toml.go +++ b/toml.go @@ -52,9 +52,11 @@ func (t *TomlTree) HasPath(keys []string) bool { // Keys returns the keys of the toplevel tree. // Warning: this is a costly operation. func (t *TomlTree) Keys() []string { - var keys []string + keys := make([]string, len(t.values)) + i := 0 for k := range t.values { - keys = append(keys, k) + keys[i] = k + i++ } return keys }