2
2
mirror of https://github.com/Hilbis/Hilbish synced 2025-04-14 17:43:22 +00:00

perf: preallocate history slice

This commit is contained in:
TorchedSammy 2022-11-30 13:20:00 -04:00
parent bd4e0df7b3
commit 06102ebdae
Signed by: sammyette
GPG Key ID: 904FC49417B44DCD

View File

@ -73,13 +73,13 @@ func newFileHistory(path string) *fileHistory {
} }
} }
itms := []string{""}
lines := strings.Split(string(data), "\n") lines := strings.Split(string(data), "\n")
itms := make([]string, len(lines) - 1)
for i, l := range lines { for i, l := range lines {
if i == len(lines) - 1 { if i == len(lines) - 1 {
continue continue
} }
itms = append(itms, l) itms[i] = l
} }
f, err := os.OpenFile(path, os.O_APPEND | os.O_WRONLY | os.O_CREATE, 0755) f, err := os.OpenFile(path, os.O_APPEND | os.O_WRONLY | os.O_CREATE, 0755)
if err != nil { if err != nil {