     : range != nil ? _ns.compare(
       aString,
       options: mask,
-      range: _toNSRange(range!)
+      range: _toRelativeNSRange(range!)
     )
 
     : !mask.isEmpty ? _ns.compare(aString, options: mask)

    R : RangeExpression
  >(for aRange: R) -> Range<Index> where R.Bound == Index {
    return _range(
      _ns.paragraphRange(for: _toNSRange(aRange.relative(to: self))))
  }
#endif


    return self._ephemeralString._bridgeToObjectiveC()
  }

  // self can be a Substring so we need to subtract/add this offset when
  // passing _ns to the Foundation APIs. Will be 0 if self is String.
  @_inlineable
  @_versioned
  internal var _substringOffset: Int {
    return self.startIndex.encodedOffset
  }

  /// Return an `Index` corresponding to the given offset in our UTF-16
  /// representation.
  func _index(_ utf16Index: Int) -> Index {
    return Index(encodedOffset: utf16Index + _substringOffset)
  }

  @_inlineable
  @_versioned
  internal func _toRelativeNSRange(_ r: Range<String.Index>) -> NSRange {
    return NSRange(
      location: r.lowerBound.encodedOffset - _substringOffset,
      length: r.upperBound.encodedOffset - r.lowerBound.encodedOffset)
  }

  /// Return a `Range<Index>` corresponding to the given `NSRange` of
