From 81307bd24f4b29975cf1ccd231cb18946badacda Mon Sep 17 00:00:00 2001 From: Ole Begemann Date: Wed, 1 Aug 2018 16:29:13 +0200 Subject: [PATCH] Fix Unmanaged.fromOpaque() usage in class Thread (#542) 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 -> UnsafeRawPointer conversion. --- Sources/NIO/Thread.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/NIO/Thread.swift b/Sources/NIO/Thread.swift index 4eca22058..c5f5da709 100644 --- a/Sources/NIO/Thread.swift +++ b/Sources/NIO/Thread.swift @@ -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.fromOpaque((p as UnsafeMutableRawPointer?)!.assumingMemoryBound(to: ThreadBox.self)).takeRetainedValue() + let b = Unmanaged.fromOpaque((p as UnsafeMutableRawPointer?)!).takeRetainedValue() let body = b.value.body let name = b.value.name