Skip to content

Commit f5a188b

Browse files
committed
Removes _validateIndex(_:file:line:)
1 parent 625fe32 commit f5a188b

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

Foundation/NSOrderedSet.swift

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -132,11 +132,6 @@ open class NSOrderedSet : NSObject, NSCopying, NSMutableCopying, NSSecureCoding,
132132
return 0..<count
133133
}
134134

135-
/// Checks that an index is valid: 0 ≤ `index` ≤ `count`.
136-
internal func _validateIndex(_ index: Int, file: StaticString = #file, line: UInt = #line) {
137-
precondition(index <= count && index >= 0, "\(self): Index out of bounds", file: file, line: line)
138-
}
139-
140135
/// Checks that an index is valid for subscripting: 0 ≤ `index` < `count`.
141136
internal func _validateSubscript(_ index: Int, file: StaticString = #file, line: UInt = #line) {
142137
precondition(_indices.contains(index), "\(self): Index out of bounds", file: file, line: line)
@@ -351,7 +346,7 @@ extension NSOrderedSet {
351346
open class NSMutableOrderedSet : NSOrderedSet {
352347

353348
open func insert(_ object: Any, at idx: Int) {
354-
_validateIndex(idx)
349+
precondition(idx <= count && idx >= 0, "\(self): Index out of bounds")
355350

356351
let value = __SwiftValue.store(object)
357352

@@ -454,14 +449,18 @@ extension NSMutableOrderedSet {
454449
}
455450
}
456451

452+
/// Sets the object at the specified index of the mutable ordered set.
453+
///
454+
/// - Parameters:
455+
/// - obj: The object to be set.
456+
/// - idx: The index. If the index is equal to `count`, then it appends
457+
/// the object. Otherwise it replaces the object at the index with the
458+
/// given object.
457459
open func setObject(_ obj: Any, at idx: Int) {
458-
_validateIndex(idx)
459-
let object = __SwiftValue.store(obj)
460-
_storage.insert(object)
461-
if idx == _orderedStorage.count {
462-
_orderedStorage.append(object)
460+
if idx == count {
461+
insert(obj, at: idx)
463462
} else {
464-
_orderedStorage[idx] = object
463+
replaceObject(at: idx, with: obj)
465464
}
466465
}
467466

0 commit comments

Comments
 (0)