Skip to content

Commit

Permalink
Fix Unmanaged.fromOpaque() usage in class Thread (#542)
Browse files Browse the repository at this point in the history
Motivation:

As discussed with Andrew Trick on the Swift Forums, the additional call
to assumingMemoryBound(to:) is redundant here. Unmanaged.fromOpaque
takes a raw pointer, and p is just that.

See https://forums.swift.org/t/withunsafetypepunnedpointer/14540/9
for the discussion.

Modifications:

Deleted an unnecessary call to assumingMemoryBound(to:). With this
change, we follow the intended usage of Unmanaged more closely.

Result:

No material change. We save one redundant UnsafeRawPointer ->
UnsafePointer<ThreadBox> -> UnsafeRawPointer conversion.
  • Loading branch information
ole authored and Lukasa committed Aug 1, 2018
1 parent beadc98 commit 81307bd
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion Sources/NIO/Thread.swift
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ final class Thread {
let box = ThreadBox(tuple)
let res = pthread_create(&pt, nil, { p in
// Cast to UnsafeMutableRawPointer? and force unwrap to make the same code work on macOS and Linux.
let b = Unmanaged<ThreadBox>.fromOpaque((p as UnsafeMutableRawPointer?)!.assumingMemoryBound(to: ThreadBox.self)).takeRetainedValue()
let b = Unmanaged<ThreadBox>.fromOpaque((p as UnsafeMutableRawPointer?)!).takeRetainedValue()

let body = b.value.body
let name = b.value.name
Expand Down

0 comments on commit 81307bd

Please sign in to comment.