@@ -9299,29 +9299,14 @@ are no pointers to it. As such, it is illegal to move a scoped object.
9299
9299
template scoped (T)
9300
9300
if (is (T == class ))
9301
9301
{
9302
- // _d_newclass now use default GC alignment (looks like (void*).sizeof * 2 for
9303
- // small objects). We will just use the maximum of filed alignments.
9304
- enum alignment = __traits(classInstanceAlignment, T);
9305
- alias aligned = _alignUp! alignment;
9306
-
9307
9302
static struct Scoped
9308
9303
{
9309
- // Addition of `alignment` is required as `Scoped_store` can be misaligned in memory.
9310
- private void [aligned( __traits(classInstanceSize, T) + size_t .sizeof) + alignment] Scoped_store = void ;
9304
+ private align (__traits(classInstanceAlignment, T))
9305
+ void [__traits(classInstanceSize, T)] buffer = void ;
9311
9306
9312
9307
@property inout (T) Scoped_payload() inout
9313
9308
{
9314
- void * alignedStore = cast (void * ) aligned(cast (size_t ) Scoped_store.ptr);
9315
- // As `Scoped` can be unaligned moved in memory class instance should be moved accordingly.
9316
- immutable size_t d = alignedStore - Scoped_store.ptr;
9317
- size_t * currD = cast (size_t * ) &Scoped_store[$ - size_t .sizeof];
9318
- if (d != * currD)
9319
- {
9320
- import core.stdc.string : memmove;
9321
- memmove(alignedStore, Scoped_store.ptr + * currD, __traits(classInstanceSize, T));
9322
- * currD = d;
9323
- }
9324
- return cast (inout (T)) alignedStore;
9309
+ return cast (inout (T)) buffer.ptr;
9325
9310
}
9326
9311
alias Scoped_payload this ;
9327
9312
@@ -9330,9 +9315,7 @@ if (is(T == class))
9330
9315
9331
9316
~this ()
9332
9317
{
9333
- // `destroy` will also write .init but we have no functions in druntime
9334
- // for deterministic finalization and memory releasing for now.
9335
- .destroy (Scoped_payload);
9318
+ .destroy ! false (Scoped_payload);
9336
9319
}
9337
9320
}
9338
9321
@@ -9344,10 +9327,7 @@ if (is(T == class))
9344
9327
import core.lifetime : emplace, forward;
9345
9328
9346
9329
Scoped result = void ;
9347
- void * alignedStore = cast (void * ) aligned(cast (size_t ) result.Scoped_store.ptr);
9348
- immutable size_t d = alignedStore - result.Scoped_store.ptr;
9349
- * cast (size_t * ) &result.Scoped_store[$ - size_t .sizeof] = d;
9350
- emplace! (Unqual! T)(result.Scoped_store[d .. $ - size_t .sizeof], forward! args);
9330
+ emplace! (Unqual! T)(result.buffer, forward! args);
9351
9331
return result;
9352
9332
}
9353
9333
}
@@ -9434,13 +9414,6 @@ if (is(T == class))
9434
9414
destroy (* b2); // calls A's destructor for b2.a
9435
9415
}
9436
9416
9437
- private size_t _alignUp (size_t alignment)(size_t n)
9438
- if (alignment > 0 && ! ((alignment - 1 ) & alignment))
9439
- {
9440
- enum badEnd = alignment - 1 ; // 0b11, 0b111, ...
9441
- return (n + badEnd) & ~ badEnd;
9442
- }
9443
-
9444
9417
// https://issues.dlang.org/show_bug.cgi?id=6580 testcase
9445
9418
@system unittest
9446
9419
{
0 commit comments