This repository was archived by the owner on Oct 12, 2022. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +12
-11
lines changed Expand file tree Collapse file tree 1 file changed +12
-11
lines changed Original file line number Diff line number Diff line change @@ -506,20 +506,21 @@ any GC memory.
506
506
*/
507
507
void destroy (T)(ref T obj) if (is (T == struct ))
508
508
{
509
- // We need to re-initialize `obj`. Previously, the code
510
- // `auto init = cast(ubyte[])typeid(T).initializer()` was used, but
511
- // `typeid` is a runtime call and requires the `TypeInfo` object which is
512
- // not usable when compiling with -betterC. If we do `obj = T.init` then we
513
- // end up needlessly calling postblits and destructors. So, we create a
514
- // static immutable lvalue that can be re-used with subsequent calls to `destroy`
515
- shared static immutable T init = T.init;
509
+ // We need to re-initialize `obj`. Previously, an immutable static
510
+ // and memcpy were used to hold an initializer. With improved unions, this is no longer
511
+ // needed.
512
+ union UntypedInit
513
+ {
514
+ T dummy;
515
+ }
516
+ static struct UntypedStorage
517
+ {
518
+ align (T.alignof) void [T.sizeof] dummy;
519
+ }
516
520
517
521
_destructRecurse(obj);
518
522
() @trusted {
519
- import core.stdc.string : memcpy;
520
- auto dest = (cast (ubyte * ) &obj)[0 .. T.sizeof];
521
- auto src = (cast (ubyte * ) &init)[0 .. T.sizeof];
522
- memcpy(dest.ptr, src.ptr, T.sizeof);
523
+ * cast (UntypedStorage* ) &obj = cast (UntypedStorage) UntypedInit.init;
523
524
} ();
524
525
}
525
526
You can’t perform that action at this time.
0 commit comments