Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove explicit ==, hashing definitions from RawRepresentable types #2134

Merged
merged 2 commits into from
Apr 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 0 additions & 16 deletions Foundation/FileManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -829,14 +829,6 @@ public struct FileAttributeKey : RawRepresentable, Equatable, Hashable {
self.rawValue = rawValue
}

public func hash(into hasher: inout Hasher) {
hasher.combine(rawValue)
}

public static func ==(_ lhs: FileAttributeKey, _ rhs: FileAttributeKey) -> Bool {
return lhs.rawValue == rhs.rawValue
}

public static let type = FileAttributeKey(rawValue: "NSFileType")
public static let size = FileAttributeKey(rawValue: "NSFileSize")
public static let modificationDate = FileAttributeKey(rawValue: "NSFileModificationDate")
Expand Down Expand Up @@ -873,14 +865,6 @@ public struct FileAttributeType : RawRepresentable, Equatable, Hashable {
self.rawValue = rawValue
}

public func hash(into hasher: inout Hasher) {
hasher.combine(rawValue)
}

public static func ==(_ lhs: FileAttributeType, _ rhs: FileAttributeType) -> Bool {
return lhs.rawValue == rhs.rawValue
}

#if os(Windows)
internal init(attributes: WIN32_FILE_ATTRIBUTE_DATA) {
if attributes.dwFileAttributes & DWORD(FILE_ATTRIBUTE_DIRECTORY) == DWORD(FILE_ATTRIBUTE_DIRECTORY) {
Expand Down
8 changes: 0 additions & 8 deletions Foundation/HTTPCookie.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,6 @@ public struct HTTPCookiePropertyKey : RawRepresentable, Equatable, Hashable {
public init(rawValue: String) {
self.rawValue = rawValue
}

public func hash(into hasher: inout Hasher) {
hasher.combine(rawValue)
}

public static func ==(_ lhs: HTTPCookiePropertyKey, _ rhs: HTTPCookiePropertyKey) -> Bool {
return lhs.rawValue == rhs.rawValue
}
}

extension HTTPCookiePropertyKey {
Expand Down
8 changes: 0 additions & 8 deletions Foundation/NSAttributedString.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,6 @@ extension NSAttributedString {
public init(rawValue: String) {
self.rawValue = rawValue
}

public func hash(into hasher: inout Hasher) {
hasher.combine(rawValue)
}

public static func ==(left: NSAttributedString.Key, right: NSAttributedString.Key) -> Bool {
return left.rawValue == right.rawValue
}
}
}

Expand Down
8 changes: 0 additions & 8 deletions Foundation/NSCalendar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,6 @@ extension NSCalendar {
self.rawValue = rawValue
}

public func hash(into hasher: inout Hasher) {
hasher.combine(rawValue)
}

public static let gregorian = NSCalendar.Identifier("gregorian")
public static let buddhist = NSCalendar.Identifier("buddhist")
public static let chinese = NSCalendar.Identifier("chinese")
Expand Down Expand Up @@ -137,10 +133,6 @@ extension NSCalendar {
}

extension NSCalendar.Identifier {
public static func ==(_ lhs: NSCalendar.Identifier, _ rhs: NSCalendar.Identifier) -> Bool {
return lhs.rawValue == rhs.rawValue
}

public static func <(_ lhs: NSCalendar.Identifier, _ rhs: NSCalendar.Identifier) -> Bool {
return lhs.rawValue < rhs.rawValue
}
Expand Down
8 changes: 0 additions & 8 deletions Foundation/NSDecimalNumber.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,6 @@ public struct NSExceptionName : RawRepresentable, Equatable, Hashable {
public init(rawValue: String) {
self.rawValue = rawValue
}

public func hash(into hasher: inout Hasher) {
hasher.combine(rawValue)
}

public static func ==(_ lhs: NSExceptionName, _ rhs: NSExceptionName) -> Bool {
return lhs.rawValue == rhs.rawValue
}
}

extension NSExceptionName {
Expand Down
11 changes: 0 additions & 11 deletions Foundation/NSLocale.swift
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,6 @@ extension NSLocale {
self.rawValue = rawValue
}

public func hash(into hasher: inout Hasher) {
hasher.combine(rawValue)
}

public static let identifier = NSLocale.Key(rawValue: "kCFLocaleIdentifierKey")
public static let languageCode = NSLocale.Key(rawValue: "kCFLocaleLanguageCodeKey")
public static let countryCode = NSLocale.Key(rawValue: "kCFLocaleCountryCodeKey")
Expand Down Expand Up @@ -213,13 +209,6 @@ extension NSLocale {
}


extension NSLocale.Key {
public static func ==(_ lhs: NSLocale.Key, _ rhs: NSLocale.Key) -> Bool {
return lhs.rawValue == rhs.rawValue
}
}


extension NSLocale {
public static let currentLocaleDidChangeNotification = NSNotification.Name(rawValue: "kCFLocaleCurrentLocaleDidChangeNotification")
}
Expand Down
8 changes: 0 additions & 8 deletions Foundation/NSNotification.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,6 @@ open class NSNotification: NSObject, NSCopying, NSCoding {
public init(rawValue: String) {
self.rawValue = rawValue
}

public func hash(into hasher: inout Hasher) {
hasher.combine(rawValue)
}

public static func ==(lhs: Name, rhs: Name) -> Bool {
return lhs.rawValue == rhs.rawValue
}
}

private(set) open var name: Name
Expand Down
8 changes: 0 additions & 8 deletions Foundation/NSString.swift
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,6 @@ extension NSString {

public let rawValue: String

public var hashValue: Int {
return self.rawValue.hashValue
}

public static func ==(_ lhs: StringTransform, _ rhs: StringTransform) -> Bool {
return lhs.rawValue == rhs.rawValue
}

public init(_ rawValue: String) {
self.rawValue = rawValue
}
Expand Down
16 changes: 0 additions & 16 deletions Foundation/NSURL.swift
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,6 @@ public struct URLResourceKey : RawRepresentable, Equatable, Hashable {
public init(_ rawValue: String) {
self.rawValue = rawValue
}

public func hash(into hasher: inout Hasher) {
hasher.combine(rawValue)
}

public static func ==(lhs: URLResourceKey, rhs: URLResourceKey) -> Bool {
return lhs.rawValue == rhs.rawValue
}
}

extension URLResourceKey {
Expand Down Expand Up @@ -197,14 +189,6 @@ public struct URLFileResourceType : RawRepresentable, Equatable, Hashable {
public init(_ rawValue: String) {
self.rawValue = rawValue
}

public func hash(into hasher: inout Hasher) {
hasher.combine(rawValue)
}

public static func ==(lhs: URLFileResourceType, rhs: URLFileResourceType) -> Bool {
return lhs.rawValue == rhs.rawValue
}
}

extension URLFileResourceType {
Expand Down
12 changes: 3 additions & 9 deletions Foundation/Progress.swift
Original file line number Diff line number Diff line change
Expand Up @@ -399,9 +399,7 @@ open class Progress : NSObject {
public let rawValue: String
public init(_ rawValue: String) { self.rawValue = rawValue }
public init(rawValue: String) { self.rawValue = rawValue }
public func hash(into hasher: inout Hasher) { hasher.combine(rawValue) }
public static func ==(_ lhs: FileOperationKind, _ rhs: FileOperationKind) -> Bool { return lhs.rawValue == rhs.rawValue }


/// Use for indicating the progress represents a download.
public static let downloading = FileOperationKind(rawValue: "NSProgressFileOperationKindDownloading")

Expand Down Expand Up @@ -478,9 +476,7 @@ public struct ProgressKind : RawRepresentable, Equatable, Hashable {
public let rawValue: String
public init(_ rawValue: String) { self.rawValue = rawValue }
public init(rawValue: String) { self.rawValue = rawValue }
public func hash(into hasher: inout Hasher) { hasher.combine(rawValue) }
public static func ==(_ lhs: ProgressKind, _ rhs: ProgressKind) -> Bool { return lhs.rawValue == rhs.rawValue }


/// Indicates that the progress being performed is related to files.
///
/// Progress of this kind is assumed to use bytes as the unit of work being done and the default implementation of `localizedDescription` takes advantage of that to return more specific text than it could otherwise.
Expand All @@ -491,9 +487,7 @@ public struct ProgressUserInfoKey : RawRepresentable, Equatable, Hashable {
public let rawValue: String
public init(_ rawValue: String) { self.rawValue = rawValue }
public init(rawValue: String) { self.rawValue = rawValue }
public func hash(into hasher: inout Hasher) { hasher.combine(rawValue) }
public static func ==(_ lhs: ProgressUserInfoKey, _ rhs: ProgressUserInfoKey) -> Bool { return lhs.rawValue == rhs.rawValue }


/// How much time is probably left in the operation, as an NSNumber containing a number of seconds.
///
/// If this value is present, then `Progress` can present a more detailed `localizedAdditionalDescription`.
Expand Down
32 changes: 0 additions & 32 deletions Foundation/Stream.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,6 @@ extension Stream {
public init(rawValue: String) {
self.rawValue = rawValue
}

public func hash(into hasher: inout Hasher) {
hasher.combine(rawValue)
}

public static func ==(lhs: Stream.PropertyKey, rhs: Stream.PropertyKey) -> Bool {
return lhs.rawValue == rhs.rawValue
}
}

public enum Status : UInt {
Expand Down Expand Up @@ -303,12 +295,6 @@ public struct StreamSocketSecurityLevel : RawRepresentable, Equatable, Hashable
public init(rawValue: String) {
self.rawValue = rawValue
}
public func hash(into hasher: inout Hasher) {
hasher.combine(rawValue)
}
public static func ==(lhs: StreamSocketSecurityLevel, rhs: StreamSocketSecurityLevel) -> Bool {
return lhs.rawValue == rhs.rawValue
}
}
extension StreamSocketSecurityLevel {
public static let none = StreamSocketSecurityLevel(rawValue: "kCFStreamSocketSecurityLevelNone")
Expand All @@ -325,12 +311,6 @@ public struct StreamSOCKSProxyConfiguration : RawRepresentable, Equatable, Hasha
public init(rawValue: String) {
self.rawValue = rawValue
}
public func hash(into hasher: inout Hasher) {
hasher.combine(rawValue)
}
public static func ==(lhs: StreamSOCKSProxyConfiguration, rhs: StreamSOCKSProxyConfiguration) -> Bool {
return lhs.rawValue == rhs.rawValue
}
}
extension StreamSOCKSProxyConfiguration {
public static let hostKey = StreamSOCKSProxyConfiguration(rawValue: "NSStreamSOCKSProxyKey")
Expand All @@ -347,12 +327,6 @@ public struct StreamSOCKSProxyVersion : RawRepresentable, Equatable, Hashable {
public init(rawValue: String) {
self.rawValue = rawValue
}
public func hash(into hasher: inout Hasher) {
hasher.combine(rawValue)
}
public static func ==(lhs: StreamSOCKSProxyVersion, rhs: StreamSOCKSProxyVersion) -> Bool {
return lhs.rawValue == rhs.rawValue
}
}
extension StreamSOCKSProxyVersion {
public static let version4 = StreamSOCKSProxyVersion(rawValue: "kCFStreamSocketSOCKSVersion4")
Expand All @@ -366,12 +340,6 @@ public struct StreamNetworkServiceTypeValue : RawRepresentable, Equatable, Hasha
public init(rawValue: String) {
self.rawValue = rawValue
}
public func hash(into hasher: inout Hasher) {
hasher.combine(rawValue)
}
public static func ==(lhs: StreamNetworkServiceTypeValue, rhs: StreamNetworkServiceTypeValue) -> Bool {
return lhs.rawValue == rhs.rawValue
}
}
extension StreamNetworkServiceTypeValue {
public static let voIP = StreamNetworkServiceTypeValue(rawValue: "kCFStreamNetworkServiceTypeVoIP")
Expand Down
8 changes: 1 addition & 7 deletions Foundation/StringEncodings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,7 @@ extension String {
}

extension String.Encoding : Hashable {
public func hash(into hasher: inout Hasher) {
hasher.combine(rawValue)
}

public static func ==(lhs: String.Encoding, rhs: String.Encoding) -> Bool {
return lhs.rawValue == rhs.rawValue
}
// ==, hash(into:) supplied by RawRepresentable
}

extension String.Encoding : CustomStringConvertible {
Expand Down
5 changes: 4 additions & 1 deletion TestFoundation/TestNSCache.swift
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,15 @@ class TestNSCache : XCTestCase {

class TestHashableCacheKey: Hashable {
let string: String
var hashValue: Int { return string.hashValue }

init(string: String) {
self.string = string
}

func hash(into hasher: inout Hasher) {
hasher.combine(string)
}

static func ==(lhs: TestHashableCacheKey,
rhs:TestHashableCacheKey) -> Bool {
return lhs.string == rhs.string
Expand Down