utf8Span
A UTF-8 span over the code units that make up this substring.
Declaration
var utf8Span: UTF8Span { get }Return Value
A UTF8Span over the code units of this substring.
Discussion
For example, if string has the bridged UTF-16 representation, the following code is accidentally quadratic because of this issue:
for word in string.split(separator: " ") {
useSpan(word.span)
}A workaround is to explicitly convert the string into its native UTF-8 representation:
var nativeString = consume string
nativeString.makeContiguousUTF8()
for word in nativeString.split(separator: " ") {
useSpan(word.span)
}This second option has linear time complexity, as expected.