Skip to content

Commit b219d41

Browse files
committed
Use copy instead of append
1 parent a0f9e96 commit b219d41

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

stringbuilder.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ func (s *StringBuilder) Remove(start int, length int) error {
8181
}
8282

8383
x := start + length
84-
s.data = append(s.data[:start], s.data[x:]...)
84+
copy(s.data[start:], s.data[x:])
8585
s.position -= length
8686

8787
return nil
@@ -96,12 +96,13 @@ func (s *StringBuilder) Insert(index int, text string) error {
9696
return fmt.Errorf("can't write outside the buffer")
9797
}
9898

99-
newLen := s.position + len(text)
99+
runeText := []rune(text)
100+
newLen := s.position + len(runeText)
100101
if newLen >= cap(s.data) {
101102
s.grow(newLen)
102103
}
103104

104-
s.data = append(s.data[:index], append([]rune(text), s.data[index:]...)...)
105+
s.data = append(s.data[:index], append(runeText, s.data[index:]...)...)
105106
s.position = newLen
106107

107108
return nil

0 commit comments

Comments
 (0)