-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[cxx-interop] Allow initializing std::map
from Swift Dictionary
#75877
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
Conversation
This adds initializers for `std::map` and `std::unordered_map` that take a Swift dictionary as a single parameter. rdar://133691563
public init(_ dictionary: Dictionary<Key, Value>) where Key: Hashable { | ||
self.init() | ||
for (key, value) in dictionary { | ||
self[key] = value |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As a future performance optimization, we could use __insertUnsafe
here to skip the check for the presence of the element in subscript
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason not to do it in this PR? Are there any concerns about that approach?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No strong reasons, but I wanted to add a simple benchmark first (in a different PR) to see if the unsafe APIs actually give us any speedup compared to the subscript.
@swift-ci please test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
public init(_ dictionary: Dictionary<Key, Value>) where Key: Hashable { | ||
self.init() | ||
for (key, value) in dictionary { | ||
self[key] = value |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason not to do it in this PR? Are there any concerns about that approach?
@swift-ci please test macOS |
1 similar comment
@swift-ci please test macOS |
@swift-ci please test Linux |
This adds initializers for
std::map
andstd::unordered_map
that take a Swift dictionary as a single parameter.rdar://133691563