Skip to content

Commit d202e2e

Browse files
committed
[gardening] Prefer Array(seq) over seq.map { $0 }
1 parent 01ffe57 commit d202e2e

File tree

8 files changed

+16
-16
lines changed

8 files changed

+16
-16
lines changed

Foundation/Data.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1650,7 +1650,7 @@ extension Data : CustomStringConvertible, CustomDebugStringConvertible, CustomRe
16501650

16511651
// Minimal size data is output as an array
16521652
if nBytes < 64 {
1653-
children.append((label: "bytes", value: self[0..<nBytes].map { $0 }))
1653+
children.append((label: "bytes", value: Array(self[0..<nBytes])))
16541654
}
16551655

16561656
let m = Mirror(self, children:children, displayStyle: Mirror.DisplayStyle.struct)

Foundation/IndexPath.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public struct IndexPath : ReferenceConvertible, Equatable, Hashable, MutableColl
3434
/// Initialize with a sequence of integers.
3535
public init<ElementSequence : Sequence>(indexes: ElementSequence)
3636
where ElementSequence.Iterator.Element == Element {
37-
_indexes = indexes.map { $0 }
37+
_indexes = Array(indexes)
3838
}
3939

4040
/// Initialize with an array literal.
@@ -159,7 +159,7 @@ public struct IndexPath : ReferenceConvertible, Equatable, Hashable, MutableColl
159159
nsIndexPath.getIndexes(elementPtr, range: NSMakeRange(0, count))
160160

161161
let buffer = UnsafeBufferPointer(start: elementPtr, count: count)
162-
_indexes = buffer.map { $0 }
162+
_indexes = Array(buffer)
163163
}
164164
}
165165

Foundation/IndexSet.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -786,7 +786,7 @@ extension IndexSet : CustomStringConvertible, CustomDebugStringConvertible, Cust
786786

787787
public var customMirror: Mirror {
788788
var c: [(label: String?, value: Any)] = []
789-
c.append((label: "ranges", value: rangeView.map { $0 }))
789+
c.append((label: "ranges", value: Array(rangeView)))
790790
return Mirror(self, children: c, displayStyle: Mirror.DisplayStyle.struct)
791791
}
792792
}

Foundation/NSDictionary.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ open class NSDictionary : NSObject, NSCopying, NSMutableCopying, NSSecureCoding,
138138
}
139139

140140
public convenience init(dictionary otherDictionary: [AnyHashable : Any]) {
141-
self.init(objects: otherDictionary.values.map { $0 }, forKeys: otherDictionary.keys.map { _SwiftValue.store($0) })
141+
self.init(objects: Array(otherDictionary.values), forKeys: otherDictionary.keys.map { _SwiftValue.store($0) })
142142
}
143143

144144
open override func isEqual(_ value: Any?) -> Bool {
@@ -156,7 +156,7 @@ open class NSDictionary : NSObject, NSCopying, NSMutableCopying, NSSecureCoding,
156156

157157
open var allKeys: [Any] {
158158
if type(of: self) === NSDictionary.self || type(of: self) === NSMutableDictionary.self {
159-
return _storage.keys.map { $0 }
159+
return Array(_storage.keys)
160160
} else {
161161
var keys = [Any]()
162162
let enumerator = keyEnumerator()
@@ -169,7 +169,7 @@ open class NSDictionary : NSObject, NSCopying, NSMutableCopying, NSSecureCoding,
169169

170170
open var allValues: [Any] {
171171
if type(of: self) === NSDictionary.self || type(of: self) === NSMutableDictionary.self {
172-
return _storage.values.map { $0 }
172+
return Array(_storage.values)
173173
} else {
174174
var values = [Any]()
175175
let enumerator = keyEnumerator()

Foundation/NSOrderedSet.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ extension NSOrderedSet {
295295

296296
public convenience init(orderedSet set: NSOrderedSet, range: NSRange, copyItems flag: Bool) {
297297
// TODO: Use the array method here when available.
298-
self.init(array: set.map { $0 }, range: range, copyItems: flag)
298+
self.init(array: Array(set), range: range, copyItems: flag)
299299
}
300300

301301
public convenience init(array: [Any]) {
@@ -331,7 +331,7 @@ extension NSOrderedSet {
331331
}
332332

333333
public convenience init(set: Set<AnyHashable>, copyItems flag: Bool) {
334-
self.init(array: set.map { $0 }, copyItems: flag)
334+
self.init(array: Array(set), copyItems: flag)
335335
}
336336
}
337337

Foundation/NSSet.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ open class NSSet : NSObject, NSCopying, NSMutableCopying, NSSecureCoding, NSCodi
150150
}
151151
})
152152
} else {
153-
self.init(array: set.map { $0 })
153+
self.init(array: Array(set))
154154
}
155155
}
156156
}
@@ -421,7 +421,7 @@ open class NSCountedSet : NSMutableSet {
421421
}
422422

423423
public convenience init(set: Set<AnyHashable>) {
424-
self.init(array: set.map { $0 })
424+
self.init(array: Array(set))
425425
}
426426

427427
public required convenience init?(coder: NSCoder) { NSUnimplemented() }

Foundation/URLComponents.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,8 +272,8 @@ public struct URLComponents : ReferenceConvertible, Hashable, Equatable, _Mutabl
272272
///
273273
/// - note: If a name-value pair in a query is empty (i.e. the query string starts with '&', ends with '&', or has "&&" within it), you get a `URLQueryItem` with a zero-length name and and a nil value. If a query's name-value pair has nothing before the equals sign, you get a zero-length name. If a query's name-value pair has nothing after the equals sign, you get a zero-length value. If a query's name-value pair has no equals sign, the query name-value pair string is the name and you get a nil value.
274274
public var queryItems: [URLQueryItem]? {
275-
get { return _handle.map { $0.queryItems?.map { return $0 as URLQueryItem } } }
276-
set { _applyMutation { $0.queryItems = newValue?.map { $0 } } }
275+
get { return _handle.map { $0.queryItems } }
276+
set { _applyMutation { $0.queryItems = newValue } }
277277
}
278278

279279
public var hashValue: Int {

TestFoundation/TestNSArray.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ class TestNSArray : XCTestCase {
400400
}
401401
mutableStringsInput1.sort(comparator)
402402
mutableStringsInput2.sort(options: [], usingComparator: comparator)
403-
XCTAssertTrue(mutableStringsInput1.isEqual(to: mutableStringsInput2.map { $0 }))
403+
XCTAssertTrue(mutableStringsInput1.isEqual(to: Array(mutableStringsInput2)))
404404
}
405405

406406
func test_equality() {
@@ -410,14 +410,14 @@ class TestNSArray : XCTestCase {
410410

411411
XCTAssertTrue(array1 == array2)
412412
XCTAssertTrue(array1.isEqual(array2))
413-
XCTAssertTrue(array1.isEqual(to: array2.map { $0 }))
413+
XCTAssertTrue(array1.isEqual(to: Array(array2)))
414414
// if 2 arrays are equal, hashes should be equal as well. But not vise versa
415415
XCTAssertEqual(array1.hash, array2.hash)
416416
XCTAssertEqual(array1.hashValue, array2.hashValue)
417417

418418
XCTAssertFalse(array1 == array3)
419419
XCTAssertFalse(array1.isEqual(array3))
420-
XCTAssertFalse(array1.isEqual(to: array3.map { $0 }))
420+
XCTAssertFalse(array1.isEqual(to: Array(array3)))
421421

422422
XCTAssertFalse(array1.isEqual(nil))
423423
XCTAssertFalse(array1.isEqual(NSObject()))

0 commit comments

Comments
 (0)