Contents

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 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.