Skip to content

Commit 392baef

Browse files
LucianoPAlmeidaCodaFi
authored andcommitted
[stdlib][Qol] SR-11295 Removing stdlib unnecessary coercions (swiftlang#27165)
* Removing unnecessary casts from stdlib * Minor adjustments * [stdlib][qol] Clean up error variable assign NSError * Removing unnecessary coercions after removing DeclRefExpr restriction.
1 parent 975aa53 commit 392baef

23 files changed

+36
-41
lines changed

benchmark/single-source/ArrayOfGenericRef.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class ConstructibleArray<T:Constructible> {
3434
array = [T]()
3535
array.reserveCapacity(1_000)
3636
for _ in 0...1_000 {
37-
array.append(T(e:e) as T)
37+
array.append(T(e:e))
3838
}
3939
}
4040
}

benchmark/single-source/ArrayOfRef.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class ConstructibleArray<T:Constructible> {
3535
array = [T]()
3636
array.reserveCapacity(1_000)
3737
for _ in 0...1_000 {
38-
array.append(T(e:e) as T)
38+
array.append(T(e:e))
3939
}
4040
}
4141
}

benchmark/single-source/StringWalk.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ import TestsUtils
6666
let ascii =
6767
"siebenhundertsiebenundsiebzigtausendsiebenhundertsiebenundsiebzig"
6868
let emoji = "👍👩‍👩‍👧‍👧👨‍👨‍👦‍👦🇺🇸🇨🇦🇲🇽👍🏻👍🏼👍🏽👍🏾👍🏿"
69-
let utf16 = emoji + "the quick brown fox" + String(emoji.reversed() as Array<Character>)
69+
let utf16 = emoji + "the quick brown fox" + String(emoji.reversed())
7070

7171
let japanese = "今回のアップデートでSwiftに大幅な改良が施され、安定していてしかも直感的に使うことができるAppleプラットフォーム向けプログラミング言語になりました。"
7272
let chinese = "Swift 是面向 Apple 平台的编程语言,功能强大且直观易用,而本次更新对其进行了全面优化。"

benchmark/single-source/StringWalk.swift.gyb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ import TestsUtils
6767
let ascii =
6868
"siebenhundertsiebenundsiebzigtausendsiebenhundertsiebenundsiebzig"
6969
let emoji = "👍👩‍👩‍👧‍👧👨‍👨‍👦‍👦🇺🇸🇨🇦🇲🇽👍🏻👍🏼👍🏽👍🏾👍🏿"
70-
let utf16 = emoji + "the quick brown fox" + String(emoji.reversed() as Array<Character>)
70+
let utf16 = emoji + "the quick brown fox" + String(emoji.reversed())
7171

7272
let japanese = "今回のアップデートでSwiftに大幅な改良が施され、安定していてしかも直感的に使うことができるAppleプラットフォーム向けプログラミング言語になりました。"
7373
let chinese = "Swift 是面向 Apple 平台的编程语言,功能强大且直观易用,而本次更新对其进行了全面优化。"

stdlib/public/Darwin/CloudKit/CKRecord.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,17 +58,17 @@ extension CKRecord {
5858

5959
@available(swift 4.2)
6060
public enum SystemType {
61-
public static let userRecord: CKRecord.RecordType = __CKRecordTypeUserRecord as CKRecord.RecordType
61+
public static let userRecord: CKRecord.RecordType = __CKRecordTypeUserRecord
6262
@available(macOS 10.12, iOS 10.0, tvOS 10.0, watchOS 3.0, *)
63-
public static let share: CKRecord.RecordType = __CKRecordTypeShare as CKRecord.RecordType
63+
public static let share: CKRecord.RecordType = __CKRecordTypeShare
6464
}
6565

6666
@available(swift 4.2)
6767
public enum SystemFieldKey {
6868
@available(macOS 10.12, iOS 10.0, tvOS 10.0, watchOS 3.0, *)
69-
public static let parent: CKRecord.FieldKey = __CKRecordParentKey as CKRecord.RecordType
69+
public static let parent: CKRecord.FieldKey = __CKRecordParentKey
7070
@available(macOS 10.12, iOS 10.0, tvOS 10.0, watchOS 3.0, *)
71-
public static let share: CKRecord.FieldKey = __CKRecordShareKey as CKRecord.RecordType
71+
public static let share: CKRecord.FieldKey = __CKRecordShareKey
7272
}
7373
}
7474

stdlib/public/Darwin/CloudKit/CKShare.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
extension CKShare {
1818
@available(swift 4.2)
1919
public enum SystemFieldKey {
20-
public static let title: CKRecord.FieldKey = __CKShareTitleKey as CKRecord.FieldKey
21-
public static let thumbnailImageData: CKRecord.FieldKey = __CKShareThumbnailImageDataKey as CKRecord.FieldKey
22-
public static let shareType: CKRecord.FieldKey = __CKShareTypeKey as CKRecord.FieldKey
20+
public static let title: CKRecord.FieldKey = __CKShareTitleKey
21+
public static let thumbnailImageData: CKRecord.FieldKey = __CKShareThumbnailImageDataKey
22+
public static let shareType: CKRecord.FieldKey = __CKShareTypeKey
2323
}
2424
}
2525

stdlib/public/Darwin/CloudKit/TypealiasStrings.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ extension CKOperation {
4343
*/
4444
@available(swift 4.2)
4545
public var operationID: CKOperation.ID {
46-
get { return self.__operationID as CKOperation.ID }
46+
get { return self.__operationID }
4747
}
4848
}
4949

stdlib/public/Darwin/CoreMedia/CMTime.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ extension CMTime {
6262
}
6363

6464
public var seconds: Double {
65-
return CMTimeGetSeconds(self) as Double
65+
return CMTimeGetSeconds(self)
6666
}
6767

6868
public func convertScale(_ newTimescale: Int32, method: CMTimeRoundingMethod)

stdlib/public/Darwin/Foundation/DateComponents.swift

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -204,11 +204,7 @@ public struct DateComponents : ReferenceConvertible, Hashable, Equatable, _Mutab
204204

205205
/// Returns a `Date` calculated from the current components using the `calendar` property.
206206
public var date: Date? {
207-
if let d = _handle.map({$0.date}) {
208-
return d as Date
209-
} else {
210-
return nil
211-
}
207+
return _handle.map { $0.date }
212208
}
213209

214210
// MARK: - Generic Setter/Getters

stdlib/public/Darwin/Foundation/FileManager.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ extension FileManager {
4848
return __NSFileManagerEnumeratorAtURL(self, url, keys, mask, { (url, error) in
4949
var errorResult = true
5050
if let h = handler {
51-
errorResult = h(url as URL, error)
51+
errorResult = h(url, error)
5252
}
5353
return errorResult
5454
})

0 commit comments

Comments
 (0)