span
A span over the UTF-8 code units that make up this substring.
Declaration
var span: Span<UTF8.CodeUnit> { get }Return Value
A Span over the UTF-8 code units of this Substring.
Discussion
for word in string.split(separator: " ") {
useSpan(word.span)
}is accidentally quadratic because of this issue. 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.