Skip to content

Commit 4a13c91

Browse files
committed
[stdlib] name your constants
1 parent e8f0d52 commit 4a13c91

File tree

4 files changed

+13
-4
lines changed

4 files changed

+13
-4
lines changed

stdlib/public/core/SmallString.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,15 @@ extension _SmallString {
9393
#endif
9494
}
9595

96+
@_alwaysEmitIntoClient @inline(__always)
97+
internal static var contiguousCapacity: Int {
98+
#if _pointerBitWidth(_32) && os(watchOS)
99+
return capacity &- 2
100+
#else
101+
return capacity
102+
#endif
103+
}
104+
96105
// Get an integer equivalent to the _StringObject.discriminatedObjectRawBits
97106
// computed property.
98107
@inlinable @inline(__always)

stdlib/public/core/StringUTF8View.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ extension String.UTF8View {
409409
public var _span: Span<UTF8.CodeUnit>? {
410410
@lifetime(borrow self)
411411
borrowing get {
412-
if _guts.isSmall && _guts.count > (_SmallString.capacity &- 2) {
412+
if _guts.isSmall, _guts.count > _SmallString.contiguousCapacity {
413413
return nil
414414
}
415415
return _underlyingSpan()

stdlib/public/core/Substring.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -871,7 +871,7 @@ extension Substring.UTF8View {
871871
public var _span: Span<UTF8.CodeUnit>? {
872872
@lifetime(borrow self)
873873
borrowing get {
874-
if _wholeGuts.isSmall && _wholeGuts.count > (_SmallString.capacity &- 2) {
874+
if _wholeGuts.isSmall, _wholeGuts.count > _SmallString.contiguousCapacity {
875875
// substring is spannable only when the whole string is spannable.
876876
return nil
877877
}

stdlib/public/core/UTF8Span.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ extension String {
291291
public var _utf8Span: UTF8Span? {
292292
@lifetime(borrow self)
293293
borrowing get {
294-
if _guts.isSmall && _guts.count > (_SmallString.capacity &- 2) {
294+
if _guts.isSmall, _guts.count > _SmallString.contiguousCapacity {
295295
return nil
296296
}
297297
return unsafe UTF8Span(
@@ -426,7 +426,7 @@ extension Substring {
426426
public var _utf8Span: UTF8Span? {
427427
@lifetime(borrow self)
428428
borrowing get {
429-
if _wholeGuts.isSmall && _wholeGuts.count > (_SmallString.capacity &- 2) {
429+
if _wholeGuts.isSmall, _wholeGuts.count > _SmallString.contiguousCapacity {
430430
// substring is spannable only when the whole string is spannable.
431431
return nil
432432
}

0 commit comments

Comments
 (0)