[String.Index] Simplify and prepare for more resilience.

Simplify String.Index by sinking transcoded offsets into the .utf8
variant. This is in preparation for a more resilient index type
capable of supporting existential string indices.
This commit is contained in:
Michael Ilseman
2018-05-14 11:30:26 -07:00
parent ba65638244
commit 614016fecd
8 changed files with 217 additions and 154 deletions

View File

@@ -221,18 +221,18 @@ extension String._CharacterView : BidirectionalCollection {
/// this view's `_baseOffset`.
@inlinable // FIXME(sil-serialize-all)
internal func _toBaseIndex(_ index: Index) -> Index {
return Index(
encodedOffset: index.encodedOffset - _baseOffset,
index._cache)
var ret = index
ret._codeUnitOffset -= _baseOffset
return ret
}
/// Translates an index in the underlying base string into a view index using
/// this view's `_baseOffset`.
@inlinable // FIXME(sil-serialize-all)
internal func _toViewIndex(_ index: Index) -> Index {
return Index(
encodedOffset: index.encodedOffset + _baseOffset,
index._cache)
var ret = index
ret._codeUnitOffset += _baseOffset
return ret
}
/// The position of the first character in a nonempty character view.