[swift-users] Are structs really always pessimistically copied when calling funcs?

Jens Alfke jens at mooseyard.com
Mon Dec 7 11:10:38 CST 2015


> On Dec 6, 2015, at 5:16 PM, Karl Pickett via swift-users <swift-users at swift.org> wrote:
> 
> When I use an inout param, that is 2x as fast and doesn't re-initialize each time.  However I don't see why passing something immutably wouldn't be as fast.

Huh. That’s especially weird since the semantics of inout actually call for two copies (after the called function returns, the copy of the struct that was passed to it gets copied back into the original variable.) The compiler is often able to optimize that down to the more-expected pass-by-pointer, as in your example. So why then isn’t it able to optimize the non-inout case the same way?

—Jens
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20151207/a1444181/attachment.html>


More information about the swift-users mailing list