Skip to content

Commit 05d7232

Browse files
author
Julien "_FrnchFrgg_" RIVAUD
committed
Avoid copying the bytes in listifyString()
We can reuse the same underlying storage and just create subslices, like bytes.Split() does.
1 parent 7f0db69 commit 05d7232

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

difflib/bytes/bytes.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ func calculateRatio(matches, length int) float64 {
4949

5050
func listifyString(str []byte) (lst [][]byte) {
5151
lst = make([][]byte, len(str))
52-
for i, c := range str {
53-
lst[i] = []byte{c}
52+
for i := range str {
53+
lst[i] = str[i:i+1]
5454
}
5555
return lst
5656
}

0 commit comments

Comments
 (0)