[swift-corelibs-dev] Question about NSDecimalCopy

Morten Bek Ditlevsen bek at termestrup.dk
Mon Jan 9 04:16:25 CST 2017

Hi list,
I was looking at the NSDecimal.swift to learn a bit about the implementation of the Decimal type.
I get that a lot of the API in this type exists for compatibility reasons with the C implementation.

But I was wondering about how the NSDecimalCopy function differs from a simple assignment of one Decimal value to another.

NSDecimalCopy simply assigns each field of the struct one by one, so when would it ever be preferable to performing a simple assignment?

So basically my question is - is there any difference in the result of performing:

var a: Decimal = 1
var b: Decimal = 2
NSDecimalCopy(&b, &a)

var a: Decimal = 1
var b: Decimal = 2
b = a

Secondly - if there is no difference in the result - is it not more performant to assign the value directly?

This question also raised a question about Swift internals: If you have a pure value type (no nested reference types): Does an assignment then simply copy a chunk of memory with the size of the struct? Or is each field assigned/copied recursively?


More information about the swift-corelibs-dev mailing list