-
Notifications
You must be signed in to change notification settings - Fork 634
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
Rebind less load more #2055
Rebind less load more #2055
Conversation
Sources/NIOPosix/BaseSocket.swift
Outdated
$0.withMemoryRebound(to: sockaddr_in.self, capacity: 1) { | ||
$0.pointee | ||
} | ||
return withUnsafeMutableBytes(of: &self) { |
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.
I think this can be withUnsafeBytes(of:)
(and elsewhere)
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.
I also wonder if this function actually needs to be mutating
.
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.
This func is mutating because on older Swift releases we didn't have a version of withUnsafeBytes
that did not take an inout
as an argument. It's possible we dropped all the Swift releases where that's true, let me check.
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.
Seems to be fine, I've updated the PR with removal of the mutatings.
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
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.
Nice one!
@swift-nio-bot test this please |
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.
I like your improvements to my drive-by fix.
@swift-nio-bot test this please |
Reduce the amount of rebinding we do with sockaddr types.
Motivation:
SR-15912 recently caused a bunch of issues with compilation of NIO in the nightlies. While these were arguably Swift bugs, we're also skating pretty close to the edge by using
withMemoryRebound
here: it's often safer for us to load the structures, rather than use random pointers.Modifications:
Result:
Fewer calls with
withMemoryRebound
.