This commit is contained in:
Dmitri Gribenko
2016-03-06 02:12:59 -08:00
parent ad1428e1d6
commit fc636b94f5
7 changed files with 19 additions and 15 deletions

View File

@@ -144,7 +144,8 @@ ${orderingRequirementForComparable}
isOrderedBefore: isOrderedBefore
% end
)
return startIndex.advanced(
return advance(
startIndex,
by: numericCast(unsafeBufferPivot - bufferPointer.startIndex))
}
if let result = maybeResult {
@@ -252,7 +253,7 @@ ${orderingRequirementForComparable}
return ()
}
if didSortUnsafeBuffer == nil {
_introSort(&self, subRange: self.indices)
_introSort(&self, subRange: startIndex..<endIndex)
}
}
}
@@ -283,7 +284,7 @@ ${orderingRequirementForPredicate}
if didSortUnsafeBuffer == nil {
_introSort(
&self,
subRange: self.indices,
subRange: startIndex..<endIndex,
isOrderedBefore: escapableIsOrderedBefore)
}
}

View File

@@ -143,7 +143,7 @@ extension LazyCollection : Collection {
///
/// - Complexity: O(1) if `Index` conforms to `RandomAccessIndex`;
/// O(N) otherwise.
public var count: Index.Distance {
public var count: Base.IndexDistance {
return _base.count
}

View File

@@ -232,7 +232,7 @@ extension RangeReplaceableCollection {
public mutating func remove(at index: Index) -> Iterator.Element {
_precondition(!isEmpty, "can't remove from an empty collection")
let result: Iterator.Element = self[index]
replaceSubrange(index...index, with: EmptyCollection())
replaceSubrange(index..<next(index), with: EmptyCollection())
return result
}
@@ -262,7 +262,7 @@ extension RangeReplaceableCollection {
self = Self()
}
else {
replaceSubrange(indices, with: EmptyCollection())
replaceSubrange(startIndex..<endIndex, with: EmptyCollection())
}
}
@@ -277,7 +277,7 @@ extension RangeReplaceableCollection where SubSequence == Self {
public mutating func removeFirst() -> Iterator.Element {
_precondition(!isEmpty, "can't remove items from an empty collection")
let element = first!
self = self[startIndex.successor()..<endIndex]
self = self[next(startIndex)..<endIndex]
return element
}

View File

@@ -150,7 +150,7 @@ extension String.CharacterView : BidirectionalCollection {
var gcb0 = graphemeClusterBreakProperty.getPropertyRawValue(
unicodeScalars[start].value)
start._successorInPlace()
unicodeScalars._nextInPlace(&start)
while start != end {
// FIXME(performance): consider removing this "fast path". A branch
@@ -165,7 +165,7 @@ extension String.CharacterView : BidirectionalCollection {
break
}
gcb0 = gcb1
start._successorInPlace()
unicodeScalars._nextInPlace(&start)
}
return start._position - startIndexUTF16
@@ -191,14 +191,14 @@ extension String.CharacterView : BidirectionalCollection {
var graphemeClusterStart = end
graphemeClusterStart._predecessorInPlace()
unicodeScalars._previousInPlace(&graphemeClusterStart)
var gcb0 = graphemeClusterBreakProperty.getPropertyRawValue(
unicodeScalars[graphemeClusterStart].value)
var graphemeClusterStartUTF16 = graphemeClusterStart._position
while graphemeClusterStart != start {
graphemeClusterStart._predecessorInPlace()
unicodeScalars._previousInPlace(&graphemeClusterStart)
let gcb1 = graphemeClusterBreakProperty.getPropertyRawValue(
unicodeScalars[graphemeClusterStart].value)
if segmenter.isBoundary(gcb1, gcb0) {
@@ -257,7 +257,8 @@ extension String.CharacterView : RangeReplaceableCollection {
>(
bounds: Range<Index>, with newElements: C
) {
let rawSubRange = bounds.startIndex._base._position
let rawSubRange: Range<Int> =
bounds.startIndex._base._position
..< bounds.endIndex._base._position
let lazyUTF16 = newElements.lazy.flatMap { $0.utf16 }
_core.replaceSubrange(rawSubRange, with: lazyUTF16)

View File

@@ -145,7 +145,7 @@ extension String {
let rng = unicodeScalars
var startIndex = rng.startIndex
for _ in 0..<start {
startIndex._successorInPlace()
rng._nextInPlace(&startIndex)
}
return String(rng[startIndex..<rng.endIndex])
}

View File

@@ -74,7 +74,8 @@ extension _StringCore {
_sanityCheck(_baseAddress._isNull)
let storage = _CollectionOf<Int, UInt16>(
startIndex: 0, endIndex: self.count) {
_startIndex: 0, endIndex: self.count
) {
(i: Int) -> UInt16 in
return _cocoaStringSubscript(self, i)
}

View File

@@ -283,7 +283,8 @@ extension String.UnicodeScalarView : RangeReplaceableCollection {
>(
bounds: Range<Index>, with newElements: C
) {
let rawSubRange = bounds.startIndex._position
let rawSubRange: Range<Int> =
bounds.startIndex._position
..< bounds.endIndex._position
let lazyUTF16 = newElements.lazy.flatMap { $0.utf16 }
_core.replaceSubrange(rawSubRange, with: lazyUTF16)