Skip to content

[Foundation] Scale back struct Notification's userInfo to be in-line … #3977

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

Merged
merged 1 commit into from
Aug 5, 2016
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
2 changes: 0 additions & 2 deletions stdlib/public/SDK/Foundation/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,13 @@ add_swift_library(swiftFoundation ${SWIFT_SDK_OVERLAY_LIBRARY_BUILD_TYPES} IS_SD
IndexSetThunks.m
Measurement.swift
Notification.swift
NotificationThunks.m
NSStringEncodings.swift
PersonNameComponents.swift
TypePreservingNSNumber.mm
URL.swift
URLComponents.swift
URLRequest.swift
UUID.swift
UserInfo.swift
Hashing.swift
Hashing.m
Thunks.mm
Expand Down
37 changes: 6 additions & 31 deletions stdlib/public/SDK/Foundation/Notification.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,6 @@
@_exported import Foundation // Clang module


@_silgen_name("__NSNotificationCreate")
internal func __NSNotificationCreate(_ name: NSString, _ object: AnyObject?, _ userInfo: AnyObject?) -> NSNotification

@_silgen_name("__NSNotificationUserInfo")
internal func __NSNotificationUserInfo(_ notif: NSNotification) -> AnyObject?

/**
`Notification` encapsulates information broadcast to observers via a `NotificationCenter`.
*/
Expand All @@ -34,12 +28,12 @@ public struct Notification : ReferenceConvertible, Equatable, Hashable {
public var object: Any?

/// Storage for values or objects related to this notification.
public var userInfo: [String : Any]?
public var userInfo: [AnyHashable : Any]?

/// Initialize a new `Notification`.
///
/// The default value for `userInfo` is nil.
public init(name: Name, object: Any? = nil, userInfo: [String : Any]? = nil) {
public init(name: Name, object: Any? = nil, userInfo: [AnyHashable : Any]? = nil) {
self.name = name
self.object = object
self.userInfo = userInfo
Expand All @@ -61,8 +55,6 @@ public struct Notification : ReferenceConvertible, Equatable, Hashable {
public typealias Name = NSNotification.Name

/// Compare two notifications for equality.
///
/// - note: Notifications that contain non NSObject values in userInfo will never compare as equal. This is because the type information is not preserved in the `userInfo` dictionary.
public static func ==(lhs: Notification, rhs: Notification) -> Bool {
if lhs.name.rawValue != rhs.name.rawValue {
return false
Expand All @@ -80,10 +72,8 @@ public struct Notification : ReferenceConvertible, Equatable, Hashable {
}
if let lhsUserInfo = lhs.userInfo {
if let rhsUserInfo = rhs.userInfo {
if lhsUserInfo.count != rhsUserInfo.count {
return false
}
return _NSUserInfoDictionary.compare(lhsUserInfo, rhsUserInfo)
// user info must be compared in the object form since the userInfo in swift is not comparable
return lhs._bridgeToObjectiveC() == rhs._bridgeToObjectiveC()
} else {
return false
}
Expand Down Expand Up @@ -116,11 +106,7 @@ extension Notification : _ObjectiveCBridgeable {

@_semantics("convertToObjectiveC")
public func _bridgeToObjectiveC() -> NSNotification {
if let info = userInfo {
return __NSNotificationCreate(name.rawValue as NSString, object.map { $0 as AnyObject }, _NSUserInfoDictionary.bridgeValue(from: info))
}

return NSNotification(name: name, object: object, userInfo: nil)
return NSNotification(name: name, object: object, userInfo: userInfo)
}

public static func _forceBridgeFromObjectiveC(_ x: NSNotification, result: inout Notification?) {
Expand All @@ -130,18 +116,7 @@ extension Notification : _ObjectiveCBridgeable {
}

public static func _conditionallyBridgeFromObjectiveC(_ x: NSNotification, result: inout Notification?) -> Bool {
if let userInfo = __NSNotificationUserInfo(x) {
if let info : [String : Any]? = _NSUserInfoDictionary.bridgeReference(from: userInfo) {
result = Notification(name: x.name, object: x.object, userInfo: info)
return true
} else {
result = nil
return false // something terrible went wrong...
}
} else {
result = Notification(name: x.name, object: x.object, userInfo: nil)
}

result = Notification(name: x.name, object: x.object, userInfo: x.userInfo)
return true
}

Expand Down
31 changes: 0 additions & 31 deletions stdlib/public/SDK/Foundation/NotificationThunks.m

This file was deleted.

224 changes: 0 additions & 224 deletions stdlib/public/SDK/Foundation/UserInfo.swift

This file was deleted.

Loading