From 06102ebdaeb8664005632c4ed935a8b89b6ef5a0 Mon Sep 17 00:00:00 2001 From: TorchedSammy <38820196+TorchedSammy@users.noreply.github.com> Date: Wed, 30 Nov 2022 13:20:00 -0400 Subject: [PATCH] perf: preallocate history slice --- history.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/history.go b/history.go index a8eb089..51ccf27 100644 --- a/history.go +++ b/history.go @@ -73,13 +73,13 @@ func newFileHistory(path string) *fileHistory { } } - itms := []string{""} lines := strings.Split(string(data), "\n") + itms := make([]string, len(lines) - 1) for i, l := range lines { if i == len(lines) - 1 { continue } - itms = append(itms, l) + itms[i] = l } f, err := os.OpenFile(path, os.O_APPEND | os.O_WRONLY | os.O_CREATE, 0755) if err != nil {