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.
This commit is contained in:
Kevin Burke
2017-05-03 21:02:36 -07:00
committed by Thomas Pelletier
parent fe206efb84
commit 76c552dcd7
+4 -2
View File
@@ -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
}