Skip to content

Commit 9a6ea01

Browse files
committed
[stdlib] update doc-comments and add a code comment
1 parent cd1b2d8 commit 9a6ea01

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

stdlib/public/core/StringCreate.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,8 @@ extension String {
316316
unsafe String._uncheckedFromUTF8($0)
317317
}
318318
#if os(watchOS) && _pointerBitWidth(_32)
319+
// Required for compatibility with some small strings that
320+
// may be encoded in the 32-bit slice of watchOS binaries.
319321
if str._wholeGuts.isSmall,
320322
str._wholeGuts.count > _SmallString.contiguousCapacity() {
321323
new.reserveCapacity(_SmallString.capacity + 1)

stdlib/public/core/StringProtocol.swift

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -177,17 +177,19 @@ extension StringProtocol {
177177

178178
// Contiguous UTF-8 strings
179179
extension String {
180-
/// Returns whether this string is capable of providing access to
181-
/// validly-encoded UTF-8 contents in contiguous memory in O(1) time.
180+
/// Returns whether this string's storage contains
181+
/// validly-encoded UTF-8 contents in contiguous memory.
182182
///
183-
/// Contiguous strings always operate in O(1) time for withUTF8 and always
184-
/// give a result for String.UTF8View.withContiguousStorageIfAvailable.
183+
/// Contiguous strings always operate in O(1) time for withUTF8, always give
184+
/// a result for String.UTF8View.withContiguousStorageIfAvailable, and always
185+
/// return a non-nil value from `String._utf8Span` and `String.UTF8View._span`.
185186
/// Contiguous strings also benefit from fast-paths and better optimizations.
186-
///
187187
@_alwaysEmitIntoClient
188188
public var isContiguousUTF8: Bool {
189189
if _guts.isFastUTF8 {
190190
#if os(watchOS) && _pointerBitWidth(_32)
191+
// Required for compatibility with some small strings that
192+
// may be encoded in the 32-bit slice of watchOS binaries.
191193
if _guts.isSmall && _guts.count > _SmallString.contiguousCapacity() {
192194
return false
193195
}
@@ -233,13 +235,14 @@ extension String {
233235

234236
// Contiguous UTF-8 strings
235237
extension Substring {
236-
/// Returns whether this string is capable of providing access to
237-
/// validly-encoded UTF-8 contents in contiguous memory in O(1) time.
238+
/// Returns whether this string's storage contains
239+
/// validly-encoded UTF-8 contents in contiguous memory.
238240
///
239-
/// Contiguous strings always operate in O(1) time for withUTF8 and always
240-
/// give a result for String.UTF8View.withContiguousStorageIfAvailable.
241+
/// Contiguous strings always operate in O(1) time for withUTF8, always give
242+
/// a result for Substring.UTF8View.withContiguousStorageIfAvailable, and
243+
/// always return a non-nil value from `Substring._utf8Span` and
244+
/// `Substring.UTF8View._span`.
241245
/// Contiguous strings also benefit from fast-paths and better optimizations.
242-
///
243246
@_alwaysEmitIntoClient
244247
public var isContiguousUTF8: Bool { return self.base.isContiguousUTF8 }
245248

0 commit comments

Comments
 (0)