Skip to content

Commit 7f30103

Browse files
committed
[String] UTF8View implements withContiguousStorageIfAvailable
1 parent dba641c commit 7f30103

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

stdlib/public/core/StringUTF8View.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,3 +510,13 @@ extension String.Index {
510510
return target._guts.isOnUnicodeScalarBoundary(self)
511511
}
512512
}
513+
514+
extension String.UTF8View {
515+
@inlinable
516+
public func withContiguousStorageIfAvailable<R>(
517+
_ body: (UnsafeBufferPointer<Element>) throws -> R
518+
) rethrows -> R? {
519+
guard _guts.isFastUTF8 else { return nil }
520+
return try _guts.withFastUTF8(body)
521+
}
522+
}

0 commit comments

Comments
 (0)