mirror of
https://github.com/kovidgoyal/kitty
synced 2026-06-08 14:18:26 +02:00
Allow specifying initial capacity when splitting lines
This commit is contained in:
@@ -54,8 +54,12 @@ func (self *ScanLines) Text() string {
|
|||||||
return self.scanner.Text()
|
return self.scanner.Text()
|
||||||
}
|
}
|
||||||
|
|
||||||
func Splitlines(x string) []string {
|
func Splitlines(x string, expected_number_of_lines ...int) (ans []string) {
|
||||||
ans := make([]string, 0, 8)
|
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))
|
scanner := bufio.NewScanner(strings.NewReader(x))
|
||||||
for scanner.Scan() {
|
for scanner.Scan() {
|
||||||
ans = append(ans, scanner.Text())
|
ans = append(ans, scanner.Text())
|
||||||
|
|||||||
Reference in New Issue
Block a user