Skip to content

Commit 4b31761

Browse files
committed
Inline only part of the append(_:) length check
Gets most of the performance win without most of the code size loss.
1 parent 435880c commit 4b31761

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

stdlib/public/core/StringGuts.swift

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -989,12 +989,10 @@ extension _StringGuts {
989989
@inlinable // @testable
990990
internal
991991
mutating func append(_ other: _StringGuts) {
992-
// FIXME(TODO: JIRA): shouldn't _isEmptySingleton be sufficient?
993-
if _isEmptySingleton || self.count == 0 && !_object.isNative {
994-
// We must be careful not to discard any capacity that
995-
// may have been reserved for the append -- this is why
996-
// we check for the empty string singleton rather than
997-
// a zero `count` above.
992+
// We inline only the _isEmptySingleton check because it can often be
993+
// proven or disproven at compile time. A full length check is often
994+
// inconclusive.
995+
if _isEmptySingleton {
998996
self = other
999997
return
1000998
}
@@ -1004,6 +1002,15 @@ extension _StringGuts {
10041002
@usableFromInline
10051003
internal
10061004
mutating func _appendSlow(_ other: _StringGuts) {
1005+
// FIXME(TODO: JIRA): shouldn't _isEmptySingleton be sufficient?
1006+
if self.count == 0 && !_object.isNative {
1007+
// We must be careful not to discard any capacity that
1008+
// may have been reserved for the append -- this is why
1009+
// we check for the empty string singleton rather than
1010+
// a zero `count` above.
1011+
self = other
1012+
return
1013+
}
10071014
if _slowPath(other._isOpaque) {
10081015
_opaqueAppend(opaqueOther: other)
10091016
return

0 commit comments

Comments
 (0)