File tree Expand file tree Collapse file tree 2 files changed +16
-0
lines changed
Expand file tree Collapse file tree 2 files changed +16
-0
lines changed Original file line number Diff line number Diff line change @@ -39,9 +39,15 @@ public protocol Enum: RawRepresentable, Hashable {
3939}
4040
4141extension Enum {
42+ #if swift(>=4.2)
43+ public func hash( into hasher: inout Hasher ) {
44+ hasher. combine ( rawValue)
45+ }
46+ #else // swift(>=4.2)
4247 public var hashValue : Int {
4348 return rawValue
4449 }
50+ #endif // swift(>=4.2)
4551
4652 /// Internal convenience property representing the name of the enum value (or
4753 /// `nil` if it is an `UNRECOGNIZED` value or doesn't provide names).
Original file line number Diff line number Diff line change @@ -68,9 +68,11 @@ fileprivate class InternPool {
6868 }
6969}
7070
71+ #if !swift(>=4.2)
7172// Constants for FNV hash http://tools.ietf.org/html/draft-eastlake-fnv-03
7273private let i_2166136261 = Int ( bitPattern: 2166136261 )
7374private let i_16777619 = Int ( 16777619 )
75+ #endif
7476
7577/// An immutable bidirectional mapping between field/enum-case names
7678/// and numbers, used to record field names for text-based
@@ -127,13 +129,21 @@ public struct _NameMap: ExpressibleByDictionaryLiteral {
127129 }
128130 }
129131
132+ #if swift(>=4.2)
133+ public func hash( into hasher: inout Hasher ) {
134+ for byte in utf8Buffer {
135+ hasher. combine ( byte)
136+ }
137+ }
138+ #else // swift(>=4.2)
130139 public var hashValue : Int {
131140 var h = i_2166136261
132141 for byte in utf8Buffer {
133142 h = ( h ^ Int ( byte) ) &* i_16777619
134143 }
135144 return h
136145 }
146+ #endif // swift(>=4.2)
137147
138148 public static func == ( lhs: Name , rhs: Name ) -> Bool {
139149 if lhs. utf8Buffer. count != rhs. utf8Buffer. count {
You can’t perform that action at this time.
0 commit comments