From 8d0452d375ef5a6713bddf2bdadae46789c0d923 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 9 Feb 2023 12:59:40 +0530 Subject: [PATCH] Allow specifying initial capacity when splitting lines --- tools/utils/strings.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tools/utils/strings.go b/tools/utils/strings.go index c1905e2e8..39932c63a 100644 --- a/tools/utils/strings.go +++ b/tools/utils/strings.go @@ -54,8 +54,12 @@ func (self *ScanLines) Text() string { return self.scanner.Text() } -func Splitlines(x string) []string { - ans := make([]string, 0, 8) +func Splitlines(x string, expected_number_of_lines ...int) (ans []string) { + if len(expected_number_of_lines) > 0 { + ans = make([]string, 0, expected_number_of_lines[0]) + } else { + ans = make([]string, 0, 8) + } scanner := bufio.NewScanner(strings.NewReader(x)) for scanner.Scan() { ans = append(ans, scanner.Text())