Skip to content

[5.0] Overlays: Modernize hashing for Selector and CGFloat #21464

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

Closed
Closed
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
15 changes: 15 additions & 0 deletions stdlib/public/SDK/CoreGraphics/CGFloat.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,21 @@ extension CGFloat : Hashable {
public var hashValue: Int {
return native.hashValue
}

/// Hashes the essential components of this value by feeding them into the
/// given hasher.
///
/// - Parameter hasher: The hasher to use when combining the components
/// of this instance.
@inlinable @_transparent
public func hash(into hasher: inout Hasher) {
hasher.combine(native)
}

@inlinable @_transparent
public func _rawHashValue(seed: Int) -> Int {
return native._rawHashValue(seed: seed)
}
}

% for dst_ty in all_integer_types(word_bits):
Expand Down
19 changes: 4 additions & 15 deletions stdlib/public/SDK/ObjectiveC/ObjectiveC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -112,21 +112,10 @@ public struct Selector : ExpressibleByStringLiteral {
}
}

extension Selector : Equatable, Hashable {
public static func ==(lhs: Selector, rhs: Selector) -> Bool {
return sel_isEqual(lhs, rhs)
}

/// The hash value.
///
/// **Axiom:** `x == y` implies `x.hashValue == y.hashValue`
///
/// - Note: the hash value is not guaranteed to be stable across
/// different invocations of the same program. Do not persist the
/// hash value across program runs.
public var hashValue: Int {
return ptr.hashValue
}
extension Selector: Equatable, Hashable {
// Note: The implementations for `==` and `hash(into:)` are synthesized by the
// compiler. The generated implementations use the value of `ptr` as the basis
// for equality.
}

extension Selector : CustomStringConvertible {
Expand Down