[Issue 17736] bigint opunary should be better performing
    via Digitalmars-d-bugs 
    digitalmars-d-bugs at puremagic.com
       
    Wed Aug  9 18:25:35 PDT 2017
    
    
  
https://issues.dlang.org/show_bug.cgi?id=17736
hsteoh at quickfur.ath.cx changed:
           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |hsteoh at quickfur.ath.cx
--- Comment #1 from hsteoh at quickfur.ath.cx ---
I notice also that binary operators on BigInt (even the opOpAssign ones like
+=) will create new instances of BigInt rather than update in-place.
One trouble with updating in-place is that it makes BigInt assignment either
expensive (always copy) or exhibit reference semantics:
---
BigInt x = 1;
BigInt y = x;
++y;
writeln(x); // will this print 1 or 2?
---
If I understand the BigInt design correctly, reference semantics are *not*
desirable because we want BigInt to be more-or-less a drop-in replacement of
fixed-size ints, and lots of code will break in subtle ways if the by-value
semantics was substituted with by-reference semantics.
One thought is that if BigInt uses some sort of reference-counting scheme, then
if the refcount is 1 we can update in-place, otherwise allocate a new BigInt to
hold the result as usual.
--
    
    
More information about the Digitalmars-d-bugs
mailing list