An idea for using ccall less in BigFloat operations

I got an idea for a way to slightly decrease the ccall-ing of libmpfr within the Base.MPFR module, which implements BigFloat.

Julia defines the BigFloat type as a mutable struct with a number of fields, and it seems like it could be worthwhile to mutate the fields directly in more places withing mpfr.jl, instead of calling C:

For example, currently the method -(::BigFloat) in mpfr.jl ccalls mpfr_neg:

The ccall overhead seems unnecessary however, as all that’s necessary for implementing -(::BigFloat) is copying the contents and, flipping the sign field of the copy, and returning the copy.

The trouble is with the BigFloat field that holds the mantissa, _d. It’s a String, an immutable type, and I’m not sure how to safely copy an immutable object that’s going to be mutated by non-Julia code later. It seems an implementation of such a copy method already exists here, but I don’t understand it or feel comfortable adapting the code:

If anyone get’s around to improving -(::BigFloat) in this manner, it would probably also make sense to add abs(::BigFloat), implemented analogously. Similarly for functions that only modify the exponent.