Skip to content

Commit 8b01cb6

Browse files
authored
Merge pull request #7243 from ikesyo/gardening-seq-to-array-conversion
[gardening] Prefer `Array(seq)` over `seq.map { $0 }`
2 parents b6d5443 + e2b03a9 commit 8b01cb6

File tree

7 files changed

+9
-9
lines changed

7 files changed

+9
-9
lines changed

stdlib/private/StdlibUnittest/StdlibUnittest.swift.gyb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1324,7 +1324,7 @@ public final class TestSuite {
13241324
case .single:
13251325
return [nil]
13261326
case .parameterized(code: _, count: let count):
1327-
return (0..<count).map { $0 }
1327+
return Array(0..<count)
13281328
}
13291329
}
13301330
}

stdlib/public/SDK/Foundation/Data.swift

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

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

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

stdlib/public/SDK/Foundation/IndexPath.swift

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

4242
/// Initialize with an array literal.
@@ -161,7 +161,7 @@ public struct IndexPath : ReferenceConvertible, Equatable, Hashable, MutableColl
161161
nsIndexPath.getIndexes(elementPtr, range: NSMakeRange(0, count))
162162

163163
let buffer = UnsafeBufferPointer(start: elementPtr, count: count)
164-
_indexes = buffer.map { $0 }
164+
_indexes = Array(buffer)
165165
}
166166
}
167167

stdlib/public/SDK/Foundation/IndexSet.swift

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

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

stdlib/public/SDK/Foundation/URLComponents.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,8 +287,8 @@ public struct URLComponents : ReferenceConvertible, Hashable, Equatable, _Mutabl
287287
/// - 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 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.
288288
@available(OSX 10.10, iOS 8.0, *)
289289
public var queryItems: [URLQueryItem]? {
290-
get { return _handle.map { $0.queryItems?.map { return $0 as URLQueryItem } } }
291-
set { _applyMutation { $0.queryItems = newValue?.map { $0 } } }
290+
get { return _handle.map { $0.queryItems } }
291+
set { _applyMutation { $0.queryItems = newValue } }
292292
}
293293

294294
public var hashValue: Int {

test/stdlib/ArrayBridge.swift.gyb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ tests.test("testMutableArray") {
461461
let a = m as NSArray as! [NSString]
462462

463463
// Create distinct array storage with a copy of the elements in a
464-
let aCopy = a.map { $0 }
464+
let aCopy = Array(a)
465465

466466
// Modify the original mutable array
467467
m.add("goop")

validation-test/stdlib/String.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1452,7 +1452,7 @@ StringTests.test("String.replaceSubrange()/characters/range") {
14521452
var theString = test.original
14531453
let c = test.original.characters
14541454
let rangeToReplace = test.rangeSelection.range(in: c)
1455-
let newCharacters : [Character] = test.newElements.characters.map { $0 }
1455+
let newCharacters : [Character] = Array(test.newElements.characters)
14561456
theString.replaceSubrange(rangeToReplace, with: newCharacters)
14571457
expectEqual(
14581458
test.expected,

0 commit comments

Comments
 (0)