www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 20711] New: object.update requires the "update" callback to

https://issues.dlang.org/show_bug.cgi?id=20711

          Issue ID: 20711
           Summary: object.update requires the "update" callback to
                    wastefully return a copy of the updated value
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Keywords: performance
          Severity: enhancement
          Priority: P1
         Component: druntime
          Assignee: nobody puremagic.com
          Reporter: dlang-bugzilla thecybershadow.net

Here is the current implementation:

https://github.com/dlang/druntime/blob/master/src/object.d#L2670

The line in question is:

        *p = update(*p);

This seems like a wasteful copy to me, and negatively affects AAs with value
types which are large or have destructors / postblit constructors. Instead, the
update callback can just write to its ref parameter.

I propose to make object.update accept an "update" callback which returns void;
in which case, simply omit the first part of the above statement.

--
Mar 30 2020