difflib: optimize SplitLines

This commit is contained in:
Robert Williamson
2015-05-09 17:21:22 -05:00
parent 8fee7c0920
commit b65e32b7e1
2 changed files with 35 additions and 4 deletions

View File

@@ -752,9 +752,7 @@ func GetContextDiffString(diff ContextDiff) (string, error) {
// Split a string on "\n" while preserving them. The output can be used
// as input for UnifiedDiff and ContextDiff structures.
func SplitLines(s string) []string {
lines := []string{}
for _, line := range strings.Split(s, "\n") {
lines = append(lines, line+"\n")
}
lines := strings.SplitAfter(s, "\n")
lines[len(lines)-1] += "\n"
return lines
}