Skip to content

Commit 40e38c8

Browse files
authored
Merge pull request #86 from onevcat/perf-optimize-plaintext
Optimize Entry.plainText concatenation
2 parents dcabc6a + 9f1c7a9 commit 40e38c8

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

Sources/Rainbow.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,12 @@ public enum Rainbow {
8585
}
8686

8787
public var plainText: String {
88-
return segments.reduce("") { $0 + $1.text }
88+
var result = String()
89+
result.reserveCapacity(segments.reduce(0) { $0 + $1.text.utf8.count })
90+
for segment in segments {
91+
result.append(segment.text)
92+
}
93+
return result
8994
}
9095

9196
public var isPlain: Bool {

0 commit comments

Comments
 (0)