Skip to content

Commit 5625117

Browse files
committed
Merge pull request #1346 from Nirma/joinWithSeparator_guard
Rewrite joinWithSeparator's zero count separator if/else statement with an early-return if check
2 parents 13cc88f + cc2251c commit 5625117

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

stdlib/public/core/String.swift

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -644,20 +644,20 @@ extension SequenceType where Generator.Element == String {
644644
result.reserveCapacity(n)
645645
}
646646

647-
if separatorSize != 0 {
648-
var gen = generate()
649-
if let first = gen.next() {
650-
result.appendContentsOf(first)
651-
while let next = gen.next() {
652-
result.appendContentsOf(separator)
653-
result.appendContentsOf(next)
654-
}
655-
}
656-
}
657-
else {
647+
if separatorSize == 0 {
658648
for x in self {
659649
result.appendContentsOf(x)
660650
}
651+
return result
652+
}
653+
654+
var gen = generate()
655+
if let first = gen.next() {
656+
result.appendContentsOf(first)
657+
while let next = gen.next() {
658+
result.appendContentsOf(separator)
659+
result.appendContentsOf(next)
660+
}
661661
}
662662

663663
return result

0 commit comments

Comments
 (0)