Bug 20711 – object.update requires the "update" callback to wastefully return a copy of the updated value

Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P1
Component
druntime
Product
D
Version
D2
Platform
All
OS
All
Creation time
2020-03-31T05:04:00Z
Last change time
2020-03-31T09:29:44Z
Keywords
performance, pull
Assigned to
No Owner
Creator
Vladimir Panteleev

Comments

Comment #0 by dlang-bugzilla — 2020-03-31T05:04:00Z
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.
Comment #1 by dlang-bot — 2020-03-31T05:05:37Z
@CyberShadow created dlang/druntime pull request #3012 "Fix Issue 20711 - object.update requires the "update" callback to was…" fixing this issue: - Fix Issue 20711 - object.update requires the "update" callback to wastefully return a copy of the updated value https://github.com/dlang/druntime/pull/3012
Comment #2 by dlang-bot — 2020-03-31T09:29:44Z
dlang/druntime pull request #3012 "Fix Issue 20711 - object.update requires the "update" callback to was…" was merged into master: - 21c47b36383720ab48625f1a46535eb7da31d7f1 by Vladimir Panteleev: Fix Issue 20711 - object.update requires the "update" callback to wastefully return a copy of the updated value https://github.com/dlang/druntime/pull/3012