mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Rename 'subrange' to 'bounds' in non-API arguments
This commit is contained in:
committed by
Max Moiseev
parent
3910a00a35
commit
ab0a2a6044
@@ -140,10 +140,10 @@ public struct LoggingRangeReplaceableCollection<
|
||||
public mutating func replaceRange<
|
||||
C : Collection where C.Iterator.Element == Base.Iterator.Element
|
||||
>(
|
||||
subRange: Range<Base.Index>, with newElements: C
|
||||
bounds: Range<Base.Index>, with newElements: C
|
||||
) {
|
||||
++Log.replaceRange[selfType]
|
||||
base.replaceRange(subRange, with: newElements)
|
||||
base.replaceRange(bounds, with: newElements)
|
||||
}
|
||||
|
||||
public mutating func append(newElement: Base.Iterator.Element) {
|
||||
@@ -190,9 +190,9 @@ public struct LoggingRangeReplaceableCollection<
|
||||
base.removeFirst(n)
|
||||
}
|
||||
|
||||
public mutating func removeRange(subRange: Range<Base.Index>) {
|
||||
public mutating func removeRange(bounds: Range<Base.Index>) {
|
||||
++Log.removeRange[selfType]
|
||||
base.removeRange(subRange)
|
||||
base.removeRange(bounds)
|
||||
}
|
||||
|
||||
public mutating func removeAll(keepCapacity keepCapacity: Bool) {
|
||||
|
||||
@@ -2638,12 +2638,12 @@ internal enum _CollectionOperation : Equatable {
|
||||
case ReserveCapacity(capacity: Int)
|
||||
case Append
|
||||
case AppendContentsOf(count: Int)
|
||||
case ReplaceRange(subRange: Range<Int>, replacementCount: Int)
|
||||
case ReplaceRange(bounds: Range<Int>, replacementCount: Int)
|
||||
case Insert(atIndex: Int)
|
||||
case InsertContentsOf(atIndex: Int, count: Int)
|
||||
case RemoveAt(index: Int)
|
||||
case RemoveLast
|
||||
case RemoveRange(subRange: Range<Int>)
|
||||
case RemoveRange(bounds: Range<Int>)
|
||||
case RemoveAll(keepCapacity: Bool)
|
||||
|
||||
internal func _applyTo(
|
||||
@@ -2663,12 +2663,12 @@ internal enum _CollectionOperation : Equatable {
|
||||
result.appendContentsOf(
|
||||
Repeat(repeating: nextStateId, count: count))
|
||||
|
||||
case ReplaceRange(let subRange, let replacementCount):
|
||||
case ReplaceRange(let bounds, let replacementCount):
|
||||
result.replaceRange(
|
||||
subRange,
|
||||
bounds,
|
||||
with: Repeat(repeating: nextStateId, count: replacementCount))
|
||||
|
||||
let invalidIndices = subRange.startIndex..<result.endIndex
|
||||
let invalidIndices = bounds.startIndex..<result.endIndex
|
||||
result.replaceRange(
|
||||
invalidIndices,
|
||||
with: Repeat(repeating: nextStateId, count: invalidIndices.count))
|
||||
@@ -2702,10 +2702,10 @@ internal enum _CollectionOperation : Equatable {
|
||||
case RemoveLast:
|
||||
result.removeLast()
|
||||
|
||||
case RemoveRange(let subRange):
|
||||
result.removeRange(subRange)
|
||||
case RemoveRange(let bounds):
|
||||
result.removeRange(bounds)
|
||||
|
||||
let invalidIndices = subRange.startIndex..<result.endIndex
|
||||
let invalidIndices = bounds.startIndex..<result.endIndex
|
||||
result.replaceRange(
|
||||
invalidIndices,
|
||||
with: Repeat(repeating: nextStateId, count: invalidIndices.count))
|
||||
@@ -3450,9 +3450,9 @@ public protocol ${Protocol} : RangeReplaceableCollection {
|
||||
extension ${Protocol} {
|
||||
public mutating func replaceRange<
|
||||
C : Collection where C.Iterator.Element == Element
|
||||
>(subRange: Range<${Self}<Element>.Index>,
|
||||
>(bounds: Range<${Self}<Element>.Index>,
|
||||
with newElements: C) {
|
||||
base.replaceRange(subRange, with: newElements)
|
||||
base.replaceRange(bounds, with: newElements)
|
||||
}
|
||||
|
||||
public mutating func removeLast() -> Element {
|
||||
@@ -3589,16 +3589,16 @@ public struct ${Self}<T> : RangeReplaceableCollection {
|
||||
public mutating func replaceRange<
|
||||
C : Collection where C.Iterator.Element == T
|
||||
>(
|
||||
subRange: Range<${Index}>, with newElements: C
|
||||
bounds: Range<${Index}>, with newElements: C
|
||||
) {
|
||||
let oldCount = count
|
||||
elements.replaceRange(
|
||||
subRange.startIndex.position..<subRange.endIndex.position,
|
||||
bounds.startIndex.position..<bounds.endIndex.position,
|
||||
with: newElements)
|
||||
let newCount = count
|
||||
_willMutate(.ReplaceRange(
|
||||
subRange: subRange.startIndex._offset..<subRange.endIndex._offset,
|
||||
replacementCount: subRange.count + newCount - oldCount))
|
||||
bounds: bounds.startIndex._offset..<bounds.endIndex._offset,
|
||||
replacementCount: bounds.count + newCount - oldCount))
|
||||
}
|
||||
|
||||
public mutating func insert(newElement: T, atIndex i: ${Index}) {
|
||||
@@ -3630,13 +3630,13 @@ public struct ${Self}<T> : RangeReplaceableCollection {
|
||||
return elements.removeLast()
|
||||
}
|
||||
|
||||
public mutating func removeRange(subRange: Range<${Index}>) {
|
||||
if !subRange.isEmpty {
|
||||
public mutating func removeRange(bounds: Range<${Index}>) {
|
||||
if !bounds.isEmpty {
|
||||
_willMutate(.RemoveRange(
|
||||
subRange: subRange.startIndex._offset..<subRange.endIndex._offset))
|
||||
bounds: bounds.startIndex._offset..<bounds.endIndex._offset))
|
||||
}
|
||||
elements.removeRange(
|
||||
subRange.startIndex.position..<subRange.endIndex.position
|
||||
bounds.startIndex.position..<bounds.endIndex.position
|
||||
)
|
||||
}
|
||||
|
||||
@@ -3937,18 +3937,18 @@ public struct Defaulted${traversal}RangeReplaceableSlice<Element>
|
||||
public mutating func replaceRange<
|
||||
C : Collection where C.Iterator.Element == Element
|
||||
>(
|
||||
subRange: Range<Index>,
|
||||
bounds: Range<Index>,
|
||||
with newElements: C
|
||||
) {
|
||||
let startOffset = startIndex.position
|
||||
let endOffset =
|
||||
endIndex.position
|
||||
- subRange.count
|
||||
- bounds.count
|
||||
+ numericCast(newElements.count) as Int
|
||||
Index._failEarlyRangeCheck2(
|
||||
subRange.startIndex, rangeEnd: subRange.endIndex,
|
||||
bounds.startIndex, rangeEnd: bounds.endIndex,
|
||||
boundsStart: startIndex, boundsEnd: endIndex)
|
||||
base.replaceRange(subRange, with: newElements)
|
||||
base.replaceRange(bounds, with: newElements)
|
||||
startIndex = base.startIndex.advancedBy(startOffset)
|
||||
endIndex = base.startIndex.advancedBy(endOffset)
|
||||
}
|
||||
|
||||
@@ -201,24 +201,24 @@ extension _ArrayBuffer {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Copy the given subRange of this buffer into uninitialized memory
|
||||
/// starting at target. Return a pointer past-the-end of the
|
||||
|
||||
/// Copy the elements in `bounds` from this buffer into uninitialized
|
||||
/// memory starting at `target`. Return a pointer past-the-end of the
|
||||
/// just-initialized memory.
|
||||
@inline(never) // The copy loop blocks retain release matching.
|
||||
public func _uninitializedCopy(
|
||||
subRange: Range<Int>, target: UnsafeMutablePointer<Element>
|
||||
bounds: Range<Int>, target: UnsafeMutablePointer<Element>
|
||||
) -> UnsafeMutablePointer<Element> {
|
||||
_typeCheck(subRange)
|
||||
_typeCheck(bounds)
|
||||
if _fastPath(_isNative) {
|
||||
return _native._uninitializedCopy(subRange, target: target)
|
||||
return _native._uninitializedCopy(bounds, target: target)
|
||||
}
|
||||
|
||||
let nonNative = _nonNative
|
||||
|
||||
let nsSubRange = SwiftShims._SwiftNSRange(
|
||||
location:subRange.startIndex,
|
||||
length: subRange.endIndex - subRange.startIndex)
|
||||
location:bounds.startIndex,
|
||||
length: bounds.endIndex - bounds.startIndex)
|
||||
|
||||
let buffer = UnsafeMutablePointer<AnyObject>(target)
|
||||
|
||||
@@ -227,21 +227,20 @@ extension _ArrayBuffer {
|
||||
|
||||
// Make another pass to retain the copied objects
|
||||
var result = target
|
||||
for _ in subRange {
|
||||
for _ in bounds {
|
||||
result.initialize(result.memory)
|
||||
++result
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
/// Return a `_SliceBuffer` containing the given `subRange` of values
|
||||
/// from this buffer.
|
||||
public subscript(subRange: Range<Int>) -> _SliceBuffer<Element> {
|
||||
/// Returns a `_SliceBuffer` containing the elements in `bounds`.
|
||||
public subscript(bounds: Range<Int>) -> _SliceBuffer<Element> {
|
||||
get {
|
||||
_typeCheck(subRange)
|
||||
_typeCheck(bounds)
|
||||
|
||||
if _fastPath(_isNative) {
|
||||
return _native[subRange]
|
||||
return _native[bounds]
|
||||
}
|
||||
|
||||
// Look for contiguous storage in the NSArray
|
||||
@@ -253,23 +252,23 @@ extension _ArrayBuffer {
|
||||
return _SliceBuffer(
|
||||
owner: nonNative,
|
||||
subscriptBaseAddress: UnsafeMutablePointer(cocoaStorageBaseAddress),
|
||||
indices: subRange,
|
||||
indices: bounds,
|
||||
hasNativeBuffer: false)
|
||||
}
|
||||
|
||||
// No contiguous storage found; we must allocate
|
||||
let subRangeCount = subRange.count
|
||||
let boundsCount = bounds.count
|
||||
let result = _ContiguousArrayBuffer<Element>(
|
||||
count: subRangeCount, minimumCapacity: 0)
|
||||
count: boundsCount, minimumCapacity: 0)
|
||||
|
||||
// Tell Cocoa to copy the objects into our storage
|
||||
cocoa.buffer.getObjects(
|
||||
UnsafeMutablePointer(result.firstElementAddress),
|
||||
range: _SwiftNSRange(
|
||||
location: subRange.startIndex,
|
||||
length: subRangeCount))
|
||||
location: bounds.startIndex,
|
||||
length: boundsCount))
|
||||
|
||||
return _SliceBuffer(result, shiftedToStartIndex: subRange.startIndex)
|
||||
return _SliceBuffer(result, shiftedToStartIndex: bounds.startIndex)
|
||||
}
|
||||
set {
|
||||
fatalError("not implemented")
|
||||
|
||||
@@ -22,11 +22,11 @@ public protocol _ArrayBufferType : MutableCollection {
|
||||
/// Adopt the entire buffer, presenting it at the provided `startIndex`.
|
||||
init(_ buffer: _ContiguousArrayBuffer<Element>, shiftedToStartIndex: Int)
|
||||
|
||||
/// Copy the given subRange of this buffer into uninitialized memory
|
||||
/// starting at target. Return a pointer past-the-end of the
|
||||
/// Copy the elements in `bounds` from this buffer into uninitialized
|
||||
/// memory starting at `target`. Return a pointer past-the-end of the
|
||||
/// just-initialized memory.
|
||||
func _uninitializedCopy(
|
||||
subRange: Range<Int>, target: UnsafeMutablePointer<Element>
|
||||
bounds: Range<Int>, target: UnsafeMutablePointer<Element>
|
||||
) -> UnsafeMutablePointer<Element>
|
||||
|
||||
/// Get or set the index'th element.
|
||||
@@ -71,9 +71,8 @@ public protocol _ArrayBufferType : MutableCollection {
|
||||
subRange subRange: Range<Int>, with newCount: Int, elementsOf newValues: C
|
||||
)
|
||||
|
||||
/// Returns a `_SliceBuffer` containing the given `subRange` of values
|
||||
/// from this buffer.
|
||||
subscript(subRange: Range<Int>) -> _SliceBuffer<Element> {get}
|
||||
/// Returns a `_SliceBuffer` containing the elements in `bounds`.
|
||||
subscript(bounds: Range<Int>) -> _SliceBuffer<Element> {get}
|
||||
|
||||
/// Call `body(p)`, where `p` is an `UnsafeBufferPointer` over the
|
||||
/// underlying contiguous storage. If no such storage exists, it is
|
||||
|
||||
@@ -260,20 +260,20 @@ public struct ${Self}<Element>
|
||||
}
|
||||
#endif
|
||||
|
||||
/// Access the elements indicated by the given half-open `subRange`.
|
||||
/// Access the contiguous subrange of elements enclosed by `bounds`.
|
||||
///
|
||||
/// - Complexity: O(1).
|
||||
public subscript(subRange: Range<Int>) -> ArraySlice<Element> {
|
||||
public subscript(bounds: Range<Int>) -> ArraySlice<Element> {
|
||||
get {
|
||||
_checkIndex(subRange.startIndex)
|
||||
_checkIndex(subRange.endIndex)
|
||||
return ArraySlice(_buffer[subRange])
|
||||
_checkIndex(bounds.startIndex)
|
||||
_checkIndex(bounds.endIndex)
|
||||
return ArraySlice(_buffer[bounds])
|
||||
}
|
||||
set(rhs) {
|
||||
_checkIndex(subRange.startIndex)
|
||||
_checkIndex(subRange.endIndex)
|
||||
if self[subRange]._buffer.identity != rhs._buffer.identity {
|
||||
self.replaceRange(subRange, with: rhs)
|
||||
_checkIndex(bounds.startIndex)
|
||||
_checkIndex(bounds.endIndex)
|
||||
if self[bounds]._buffer.identity != rhs._buffer.identity {
|
||||
self.replaceRange(bounds, with: rhs)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -915,9 +915,9 @@ internal func _arrayOutOfPlaceReplace<
|
||||
C.Iterator.Element == B.Element,
|
||||
B.Index == Int
|
||||
>(
|
||||
inout source: B, _ subRange: Range<Int>, _ newValues: C, _ insertCount: Int
|
||||
inout source: B, _ bounds: Range<Int>, _ newValues: C, _ insertCount: Int
|
||||
) {
|
||||
let growth = insertCount - subRange.count
|
||||
let growth = insertCount - bounds.count
|
||||
let newCount = source.count + growth
|
||||
var newBuffer = Optional(
|
||||
_forceCreateUniqueMutableBuffer(
|
||||
@@ -925,7 +925,7 @@ internal func _arrayOutOfPlaceReplace<
|
||||
|
||||
_arrayOutOfPlaceUpdate(
|
||||
&source, &newBuffer,
|
||||
subRange.startIndex - source.startIndex, insertCount,
|
||||
bounds.startIndex - source.startIndex, insertCount,
|
||||
_InitializeMemoryFromCollection(newValues)
|
||||
)
|
||||
}
|
||||
@@ -947,7 +947,7 @@ internal func _growArrayCapacity(capacity: Int) -> Int {
|
||||
|
||||
% for (Self, a_Self) in arrayTypes:
|
||||
extension ${Self} {
|
||||
/// Replace the given `subRange` of elements with `newElements`.
|
||||
/// Replace the elements within `bounds` with `newElements`.
|
||||
///
|
||||
/// - Complexity: O(`subRange.count`) if `subRange.endIndex
|
||||
/// == self.endIndex` and `newElements.isEmpty`, O(N) otherwise.
|
||||
|
||||
@@ -374,30 +374,30 @@ public struct _ContiguousArrayBuffer<Element> : _ArrayBufferType {
|
||||
return __bufferPointer.value.capacity
|
||||
}
|
||||
|
||||
/// Copy the given subRange of this buffer into uninitialized memory
|
||||
/// starting at target. Return a pointer past-the-end of the
|
||||
/// Copy the elements in `bounds` from this buffer into uninitialized
|
||||
/// memory starting at `target`. Return a pointer past-the-end of the
|
||||
/// just-initialized memory.
|
||||
public func _uninitializedCopy(
|
||||
subRange: Range<Int>, target: UnsafeMutablePointer<Element>
|
||||
bounds: Range<Int>, target: UnsafeMutablePointer<Element>
|
||||
) -> UnsafeMutablePointer<Element> {
|
||||
_sanityCheck(subRange.startIndex >= 0)
|
||||
_sanityCheck(subRange.endIndex >= subRange.startIndex)
|
||||
_sanityCheck(subRange.endIndex <= count)
|
||||
_sanityCheck(bounds.startIndex >= 0)
|
||||
_sanityCheck(bounds.endIndex >= bounds.startIndex)
|
||||
_sanityCheck(bounds.endIndex <= count)
|
||||
|
||||
let c = subRange.endIndex - subRange.startIndex
|
||||
target.initializeFrom(firstElementAddress + subRange.startIndex, count: c)
|
||||
let c = bounds.endIndex - bounds.startIndex
|
||||
target.initializeFrom(firstElementAddress + bounds.startIndex, count: c)
|
||||
_fixLifetime(owner)
|
||||
return target + c
|
||||
}
|
||||
|
||||
/// Returns a `_SliceBuffer` containing the given `subRange` of values
|
||||
/// Returns a `_SliceBuffer` containing the given `bounds` of values
|
||||
/// from this buffer.
|
||||
public subscript(subRange: Range<Int>) -> _SliceBuffer<Element> {
|
||||
public subscript(bounds: Range<Int>) -> _SliceBuffer<Element> {
|
||||
get {
|
||||
return _SliceBuffer(
|
||||
owner: __bufferPointer.buffer,
|
||||
subscriptBaseAddress: subscriptBaseAddress,
|
||||
indices: subRange,
|
||||
indices: bounds,
|
||||
hasNativeBuffer: true)
|
||||
}
|
||||
set {
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
/// A *collection* that supports replacement of an arbitrary subRange
|
||||
/// A *collection* that supports replacement of an arbitrary subrange
|
||||
/// of elements with the elements of another collection.
|
||||
public protocol RangeReplaceableCollection : Collection {
|
||||
//===--- Fundamental Requirements ---------------------------------------===//
|
||||
@@ -22,17 +22,17 @@ public protocol RangeReplaceableCollection : Collection {
|
||||
/// Create an empty instance.
|
||||
init()
|
||||
|
||||
/// Replace the given `subRange` of elements with `newElements`.
|
||||
/// Replace the elements within `bounds` with `newElements`.
|
||||
///
|
||||
/// Invalidates all indices with respect to `self`.
|
||||
///
|
||||
/// - Complexity: O(`subRange.count`) if
|
||||
/// `subRange.endIndex == self.endIndex` and `newElements.isEmpty`,
|
||||
/// - Complexity: O(`bounds.count`) if
|
||||
/// `bounds.endIndex == self.endIndex` and `newElements.isEmpty`,
|
||||
/// O(`self.count` + `newElements.count`) otherwise.
|
||||
mutating func replaceRange<
|
||||
C : Collection where C.Iterator.Element == Iterator.Element
|
||||
>(
|
||||
subRange: Range<Index>, with newElements: C
|
||||
bounds: Range<Index>, with newElements: C
|
||||
)
|
||||
|
||||
/*
|
||||
@@ -156,12 +156,12 @@ public protocol RangeReplaceableCollection : Collection {
|
||||
/// - Requires: `n >= 0 && self.count >= n`.
|
||||
mutating func removeFirst(n: Int)
|
||||
|
||||
/// Remove the indicated `subRange` of elements.
|
||||
/// Remove the elements in `bounds`.
|
||||
///
|
||||
/// Invalidates all indices with respect to `self`.
|
||||
///
|
||||
/// - Complexity: O(`self.count`).
|
||||
mutating func removeRange(subRange: Range<Index>)
|
||||
mutating func removeRange(bounds: Range<Index>)
|
||||
|
||||
/// Remove all elements.
|
||||
///
|
||||
@@ -219,8 +219,8 @@ extension RangeReplaceableCollection {
|
||||
return result
|
||||
}
|
||||
|
||||
public mutating func removeRange(subRange: Range<Index>) {
|
||||
replaceRange(subRange, with: EmptyCollection())
|
||||
public mutating func removeRange(bounds: Range<Index>) {
|
||||
replaceRange(bounds, with: EmptyCollection())
|
||||
}
|
||||
|
||||
public mutating func removeFirst(n: Int) {
|
||||
|
||||
@@ -181,16 +181,15 @@ struct _SliceBuffer<Element> : _ArrayBufferType {
|
||||
return nil
|
||||
}
|
||||
|
||||
public
|
||||
func _uninitializedCopy(
|
||||
subRange: Range<Int>, target: UnsafeMutablePointer<Element>
|
||||
public func _uninitializedCopy(
|
||||
bounds: Range<Int>, target: UnsafeMutablePointer<Element>
|
||||
) -> UnsafeMutablePointer<Element> {
|
||||
_invariantCheck()
|
||||
_sanityCheck(subRange.startIndex >= startIndex)
|
||||
_sanityCheck(subRange.endIndex >= subRange.startIndex)
|
||||
_sanityCheck(subRange.endIndex <= endIndex)
|
||||
let c = subRange.count
|
||||
target.initializeFrom(subscriptBaseAddress + subRange.startIndex, count: c)
|
||||
_sanityCheck(bounds.startIndex >= startIndex)
|
||||
_sanityCheck(bounds.endIndex >= bounds.startIndex)
|
||||
_sanityCheck(bounds.endIndex <= endIndex)
|
||||
let c = bounds.count
|
||||
target.initializeFrom(subscriptBaseAddress + bounds.startIndex, count: c)
|
||||
return target + c
|
||||
}
|
||||
|
||||
@@ -270,15 +269,15 @@ struct _SliceBuffer<Element> : _ArrayBufferType {
|
||||
}
|
||||
}
|
||||
|
||||
public subscript(subRange: Range<Int>) -> _SliceBuffer {
|
||||
public subscript(bounds: Range<Int>) -> _SliceBuffer {
|
||||
get {
|
||||
_sanityCheck(subRange.startIndex >= startIndex)
|
||||
_sanityCheck(subRange.endIndex >= subRange.startIndex)
|
||||
_sanityCheck(subRange.endIndex <= endIndex)
|
||||
_sanityCheck(bounds.startIndex >= startIndex)
|
||||
_sanityCheck(bounds.endIndex >= bounds.startIndex)
|
||||
_sanityCheck(bounds.endIndex <= endIndex)
|
||||
return _SliceBuffer(
|
||||
owner: owner,
|
||||
subscriptBaseAddress: subscriptBaseAddress,
|
||||
indices: subRange,
|
||||
indices: bounds,
|
||||
hasNativeBuffer: _hasNativeBuffer)
|
||||
}
|
||||
set {
|
||||
|
||||
@@ -567,12 +567,12 @@ public func < (lhs: String.Index, rhs: String.Index) -> Bool {
|
||||
}
|
||||
|
||||
extension String {
|
||||
/// Access the characters in the given `subRange`.
|
||||
/// Access the characters in `bounds`.
|
||||
///
|
||||
/// - Complexity: O(1) unless bridging from Objective-C requires an
|
||||
/// O(N) conversion.
|
||||
public subscript(subRange: Range<Index>) -> String {
|
||||
return String(characters[subRange])
|
||||
public subscript(bounds: Range<Index>) -> String {
|
||||
return String(characters[bounds])
|
||||
}
|
||||
}
|
||||
|
||||
@@ -654,32 +654,32 @@ extension Sequence where Iterator.Element == String {
|
||||
}
|
||||
|
||||
extension String {
|
||||
/// Replace the given `subRange` of elements with `newElements`.
|
||||
/// Replace the elements in `bounds` with `newElements`.
|
||||
///
|
||||
/// Invalidates all indices with respect to `self`.
|
||||
///
|
||||
/// - Complexity: O(`subRange.count`) if `subRange.endIndex
|
||||
/// - Complexity: O(`bounds.count`) if `bounds.endIndex
|
||||
/// == self.endIndex` and `newElements.isEmpty`, O(N) otherwise.
|
||||
public mutating func replaceRange<
|
||||
C: Collection where C.Iterator.Element == Character
|
||||
>(
|
||||
subRange: Range<Index>, with newElements: C
|
||||
bounds: Range<Index>, with newElements: C
|
||||
) {
|
||||
withMutableCharacters {
|
||||
(inout v: CharacterView) in v.replaceRange(subRange, with: newElements)
|
||||
(inout v: CharacterView) in v.replaceRange(bounds, with: newElements)
|
||||
}
|
||||
}
|
||||
|
||||
/// Replace the given `subRange` of elements with `newElements`.
|
||||
/// Replace the elements in `bounds` with `newElements`.
|
||||
///
|
||||
/// Invalidates all indices with respect to `self`.
|
||||
///
|
||||
/// - Complexity: O(`subRange.count`) if `subRange.endIndex
|
||||
/// - Complexity: O(`bounds.count`) if `bounds.endIndex
|
||||
/// == self.endIndex` and `newElements.isEmpty`, O(N) otherwise.
|
||||
public mutating func replaceRange(
|
||||
subRange: Range<Index>, with newElements: String
|
||||
bounds: Range<Index>, with newElements: String
|
||||
) {
|
||||
replaceRange(subRange, with: newElements.characters)
|
||||
replaceRange(bounds, with: newElements.characters)
|
||||
}
|
||||
|
||||
/// Insert `newElement` at index `i`.
|
||||
@@ -717,14 +717,14 @@ extension String {
|
||||
}
|
||||
}
|
||||
|
||||
/// Remove the indicated `subRange` of characters.
|
||||
/// Remove the characters in `bounds`.
|
||||
///
|
||||
/// Invalidates all indices with respect to `self`.
|
||||
///
|
||||
/// - Complexity: O(`self.count`).
|
||||
public mutating func removeRange(subRange: Range<Index>) {
|
||||
public mutating func removeRange(bounds: Range<Index>) {
|
||||
withMutableCharacters {
|
||||
(inout v: CharacterView) in v.removeRange(subRange)
|
||||
(inout v: CharacterView) in v.removeRange(bounds)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -99,7 +99,7 @@ internal func _cocoaStringReadAll(
|
||||
|
||||
@inline(never) @_semantics("stdlib_binary_only") // Hide the CF dependency
|
||||
internal func _cocoaStringSlice(
|
||||
target: _StringCore, _ subRange: Range<Int>
|
||||
target: _StringCore, _ bounds: Range<Int>
|
||||
) -> _StringCore {
|
||||
_sanityCheck(target.hasCocoaBuffer)
|
||||
|
||||
@@ -111,7 +111,7 @@ internal func _cocoaStringSlice(
|
||||
|
||||
let cfResult: AnyObject = _swift_stdlib_CFStringCreateWithSubstring(
|
||||
nil, cfSelf, _swift_shims_CFRange(
|
||||
location: subRange.startIndex, length: subRange.count))
|
||||
location: bounds.startIndex, length: bounds.count))
|
||||
|
||||
return String(_cocoaString: cfResult)._core
|
||||
}
|
||||
|
||||
@@ -187,17 +187,17 @@ public struct _StringBuffer {
|
||||
/// - the buffer is uniquely-refereced, or
|
||||
/// - `oldUsedEnd` points to the end of the currently used capacity.
|
||||
///
|
||||
/// - parameter subRange: Range of the substring that the caller tries
|
||||
/// - parameter bounds: Range of the substring that the caller tries
|
||||
/// to extend.
|
||||
/// - parameter newUsedCount: The desired size of the substring.
|
||||
mutating func grow(
|
||||
subRange: Range<UnsafePointer<RawByte>>, newUsedCount: Int
|
||||
bounds: Range<UnsafePointer<RawByte>>, newUsedCount: Int
|
||||
) -> Bool {
|
||||
var newUsedCount = newUsedCount
|
||||
// The substring to be grown could be pointing in the middle of this
|
||||
// _StringBuffer. Adjust the size so that it covers the imaginary
|
||||
// substring from the start of the buffer to `oldUsedEnd`.
|
||||
newUsedCount += (subRange.startIndex - UnsafePointer(start)) >> elementShift
|
||||
newUsedCount += (bounds.startIndex - UnsafePointer(start)) >> elementShift
|
||||
|
||||
if _slowPath(newUsedCount > capacity) {
|
||||
return false
|
||||
@@ -215,13 +215,13 @@ public struct _StringBuffer {
|
||||
// place. The operation should be implemented in a thread-safe way,
|
||||
// though.
|
||||
//
|
||||
// if usedEnd == subRange.endIndex {
|
||||
// if usedEnd == bounds.endIndex {
|
||||
// usedEnd = newUsedEnd
|
||||
// return true
|
||||
// }
|
||||
let usedEndPhysicalPtr =
|
||||
UnsafeMutablePointer<UnsafeMutablePointer<RawByte>>(_storage._value)
|
||||
var expected = UnsafeMutablePointer<RawByte>(subRange.endIndex)
|
||||
var expected = UnsafeMutablePointer<RawByte>(bounds.endIndex)
|
||||
if _stdlib_atomicCompareExchangeStrongPtr(
|
||||
object: usedEndPhysicalPtr, expected: &expected, desired: newUsedEnd) {
|
||||
return true
|
||||
|
||||
@@ -266,19 +266,19 @@ extension String.CharacterView : RangeReplaceableCollection {
|
||||
self.init("")
|
||||
}
|
||||
|
||||
/// Replace the given `subRange` of elements with `newElements`.
|
||||
/// Replace the elements in `bounds` with `newElements`.
|
||||
///
|
||||
/// Invalidates all indices with respect to `self`.
|
||||
///
|
||||
/// - Complexity: O(`subRange.count`) if `subRange.endIndex
|
||||
/// - Complexity: O(`bounds.count`) if `bounds.endIndex
|
||||
/// == self.endIndex` and `newElements.isEmpty`, O(N) otherwise.
|
||||
public mutating func replaceRange<
|
||||
C: Collection where C.Iterator.Element == Character
|
||||
>(
|
||||
subRange: Range<Index>, with newElements: C
|
||||
bounds: Range<Index>, with newElements: C
|
||||
) {
|
||||
let rawSubRange = subRange.startIndex._base._position
|
||||
..< subRange.endIndex._base._position
|
||||
let rawSubRange = bounds.startIndex._base._position
|
||||
..< bounds.endIndex._base._position
|
||||
let lazyUTF16 = newElements.lazy.flatMap { $0.utf16 }
|
||||
_core.replaceRange(rawSubRange, with: lazyUTF16)
|
||||
}
|
||||
@@ -324,13 +324,13 @@ extension String.CharacterView : RangeReplaceableCollection {
|
||||
|
||||
// Algorithms
|
||||
extension String.CharacterView {
|
||||
/// Access the characters in the given `subRange`.
|
||||
/// Access the characters in `bounds`.
|
||||
///
|
||||
/// - Complexity: O(1) unless bridging from Objective-C requires an
|
||||
/// O(N) conversion.
|
||||
public subscript(subRange: Range<Index>) -> String.CharacterView {
|
||||
public subscript(bounds: Range<Index>) -> String.CharacterView {
|
||||
let unicodeScalarRange =
|
||||
subRange.startIndex._base..<subRange.endIndex._base
|
||||
bounds.startIndex._base..<bounds.endIndex._base
|
||||
return String.CharacterView(
|
||||
String(_core).unicodeScalars[unicodeScalarRange]._core)
|
||||
}
|
||||
|
||||
@@ -263,26 +263,26 @@ public struct _StringCore {
|
||||
// slicing
|
||||
|
||||
/// Returns the given sub-`_StringCore`.
|
||||
public subscript(subRange: Range<Int>) -> _StringCore {
|
||||
public subscript(bounds: Range<Int>) -> _StringCore {
|
||||
_precondition(
|
||||
subRange.startIndex >= 0,
|
||||
"subscript: subRange start precedes String start")
|
||||
bounds.startIndex >= 0,
|
||||
"subscript: subrange start precedes String start")
|
||||
|
||||
_precondition(
|
||||
subRange.endIndex <= count,
|
||||
"subscript: subRange extends past String end")
|
||||
bounds.endIndex <= count,
|
||||
"subscript: subrange extends past String end")
|
||||
|
||||
let newCount = subRange.endIndex - subRange.startIndex
|
||||
let newCount = bounds.endIndex - bounds.startIndex
|
||||
_sanityCheck(UInt(newCount) & _flagMask == 0)
|
||||
|
||||
if hasContiguousStorage {
|
||||
return _StringCore(
|
||||
baseAddress: _pointerToNth(subRange.startIndex),
|
||||
baseAddress: _pointerToNth(bounds.startIndex),
|
||||
_countAndFlags: (_countAndFlags & _flagMask) | UInt(newCount),
|
||||
owner: _owner)
|
||||
}
|
||||
#if _runtime(_ObjC)
|
||||
return _cocoaStringSlice(self, subRange)
|
||||
return _cocoaStringSlice(self, bounds)
|
||||
#else
|
||||
_sanityCheckFailure("subscript: non-native string without objc runtime")
|
||||
#endif
|
||||
@@ -570,27 +570,27 @@ extension _StringCore : Collection {
|
||||
|
||||
extension _StringCore : RangeReplaceableCollection {
|
||||
|
||||
/// Replace the given `subRange` of elements with `newElements`.
|
||||
/// Replace the elements within `bounds` with `newElements`.
|
||||
///
|
||||
/// - Complexity: O(`subRange.count`) if `subRange.endIndex
|
||||
/// - Complexity: O(`bounds.count`) if `bounds.endIndex
|
||||
/// == self.endIndex` and `newElements.isEmpty`, O(N) otherwise.
|
||||
public mutating func replaceRange<
|
||||
C: Collection where C.Iterator.Element == UTF16.CodeUnit
|
||||
>(
|
||||
subRange: Range<Int>, with newElements: C
|
||||
bounds: Range<Int>, with newElements: C
|
||||
) {
|
||||
_precondition(
|
||||
subRange.startIndex >= 0,
|
||||
"replaceRange: subRange start precedes String start")
|
||||
bounds.startIndex >= 0,
|
||||
"replaceRange: subrange start precedes String start")
|
||||
|
||||
_precondition(
|
||||
subRange.endIndex <= count,
|
||||
"replaceRange: subRange extends past String end")
|
||||
bounds.endIndex <= count,
|
||||
"replaceRange: subrange extends past String end")
|
||||
|
||||
let width = elementWidth == 2 || newElements.contains { $0 > 0x7f } ? 2 : 1
|
||||
let replacementCount = numericCast(newElements.count) as Int
|
||||
let replacedCount = subRange.count
|
||||
let tailCount = count - subRange.endIndex
|
||||
let replacedCount = bounds.count
|
||||
let tailCount = count - bounds.endIndex
|
||||
let growth = replacementCount - replacedCount
|
||||
let newCount = count + growth
|
||||
|
||||
@@ -599,7 +599,7 @@ extension _StringCore : RangeReplaceableCollection {
|
||||
// strings, i.e., when we're appending. Already-used characters
|
||||
// can only be mutated when we have a unique reference to the
|
||||
// buffer.
|
||||
let appending = subRange.startIndex == endIndex
|
||||
let appending = bounds.startIndex == endIndex
|
||||
|
||||
let existingStorage = !hasCocoaBuffer && (
|
||||
appending || isUniquelyReferencedNonObjC(&_owner)
|
||||
@@ -607,7 +607,7 @@ extension _StringCore : RangeReplaceableCollection {
|
||||
|
||||
if _fastPath(existingStorage != nil) {
|
||||
let rangeStart = UnsafeMutablePointer<UInt8>(
|
||||
_pointerToNth(subRange.startIndex))
|
||||
_pointerToNth(bounds.startIndex))
|
||||
let tailStart = rangeStart + (replacedCount << elementShift)
|
||||
|
||||
if growth > 0 {
|
||||
@@ -643,9 +643,9 @@ extension _StringCore : RangeReplaceableCollection {
|
||||
: representableAsASCII() && !newElements.contains { $0 > 0x7f } ? 1
|
||||
: 2
|
||||
))
|
||||
r.appendContentsOf(self[0..<subRange.startIndex])
|
||||
r.appendContentsOf(self[0..<bounds.startIndex])
|
||||
r.appendContentsOf(newElements)
|
||||
r.appendContentsOf(self[subRange.endIndex..<count])
|
||||
r.appendContentsOf(self[bounds.endIndex..<count])
|
||||
self = r
|
||||
}
|
||||
}
|
||||
@@ -654,10 +654,10 @@ extension _StringCore : RangeReplaceableCollection {
|
||||
if _fastPath(!hasCocoaBuffer) {
|
||||
if _fastPath(isUniquelyReferencedNonObjC(&_owner)) {
|
||||
|
||||
let subRange: Range<UnsafePointer<RawByte>>
|
||||
let bounds: Range<UnsafePointer<RawByte>>
|
||||
= UnsafePointer(_pointerToNth(0))..<UnsafePointer(_pointerToNth(count))
|
||||
|
||||
if _fastPath(nativeBuffer!.hasCapacity(n, forSubRange: subRange)) {
|
||||
if _fastPath(nativeBuffer!.hasCapacity(n, forSubRange: bounds)) {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,7 +94,7 @@ extension String {
|
||||
@available(
|
||||
*, unavailable,
|
||||
message="Slicing a String's UTF16View requires a Range<String.UTF16View.Index>, String.UTF16View.Index can be constructed from Int when Foundation is imported")
|
||||
public subscript(subRange: Range<Int>) -> UTF16View {
|
||||
public subscript(bounds: Range<Int>) -> UTF16View {
|
||||
fatalError("unavailable function can't be called")
|
||||
}
|
||||
#endif
|
||||
@@ -104,10 +104,11 @@ extension String {
|
||||
///
|
||||
/// - Complexity: O(1) unless bridging from Objective-C requires an
|
||||
/// O(N) conversion.
|
||||
public subscript(subRange: Range<Index>) -> UTF16View {
|
||||
public subscript(bounds: Range<Index>) -> UTF16View {
|
||||
return UTF16View(
|
||||
_core, offset: _toInternalIndex(subRange.startIndex._offset),
|
||||
length: subRange.endIndex._offset - subRange.startIndex._offset)
|
||||
_core,
|
||||
offset: _toInternalIndex(bounds.startIndex._offset),
|
||||
length: bounds.endIndex._offset - bounds.startIndex._offset)
|
||||
}
|
||||
|
||||
internal init(_ _core: _StringCore) {
|
||||
|
||||
@@ -226,8 +226,8 @@ extension String {
|
||||
///
|
||||
/// - Complexity: O(1) unless bridging from Objective-C requires an
|
||||
/// O(N) conversion.
|
||||
public subscript(subRange: Range<Index>) -> UTF8View {
|
||||
return UTF8View(_core, subRange.startIndex, subRange.endIndex)
|
||||
public subscript(bounds: Range<Index>) -> UTF8View {
|
||||
return UTF8View(_core, bounds.startIndex, bounds.endIndex)
|
||||
}
|
||||
|
||||
/// Returns a mirror that reflects `self`.
|
||||
|
||||
@@ -275,19 +275,19 @@ extension String.UnicodeScalarView : RangeReplaceableCollection {
|
||||
>(newElements: S) {
|
||||
_core.appendContentsOf(newElements.lazy.flatMap { $0.utf16 })
|
||||
}
|
||||
/// Replace the given `subRange` of elements with `newElements`.
|
||||
/// Replace the elements within `bounds` with `newElements`.
|
||||
///
|
||||
/// Invalidates all indices with respect to `self`.
|
||||
///
|
||||
/// - Complexity: O(`subRange.count`) if `subRange.endIndex
|
||||
/// - Complexity: O(`bounds.count`) if `bounds.endIndex
|
||||
/// == self.endIndex` and `newElements.isEmpty`, O(N) otherwise.
|
||||
public mutating func replaceRange<
|
||||
C: Collection where C.Iterator.Element == UnicodeScalar
|
||||
>(
|
||||
subRange: Range<Index>, with newElements: C
|
||||
bounds: Range<Index>, with newElements: C
|
||||
) {
|
||||
let rawSubRange = subRange.startIndex._position
|
||||
..< subRange.endIndex._position
|
||||
let rawSubRange = bounds.startIndex._position
|
||||
..< bounds.endIndex._position
|
||||
let lazyUTF16 = newElements.lazy.flatMap { $0.utf16 }
|
||||
_core.replaceRange(rawSubRange, with: lazyUTF16)
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ ${stringSubscriptComment}
|
||||
@available(
|
||||
*, unavailable,
|
||||
message="cannot subscript String with a Range<Int>, see the documentation comment for discussion")
|
||||
public subscript(subRange: Range<Int>) -> String {
|
||||
public subscript(bounds: Range<Int>) -> String {
|
||||
fatalError("unavailable function can't be called")
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user