@@ -8265,29 +8265,14 @@ are no pointers to it. As such, it is illegal to move a scoped object.
8265
8265
template scoped (T)
8266
8266
if (is (T == class ))
8267
8267
{
8268
- // _d_newclass now use default GC alignment (looks like (void*).sizeof * 2 for
8269
- // small objects). We will just use the maximum of filed alignments.
8270
- alias alignment = classInstanceAlignment! T;
8271
- alias aligned = _alignUp! alignment;
8272
-
8273
8268
static struct Scoped
8274
8269
{
8275
- // Addition of `alignment` is required as `Scoped_store` can be misaligned in memory.
8276
- private void [aligned( __traits(classInstanceSize, T) + size_t .sizeof) + alignment] Scoped_store = void ;
8270
+ private align (__traits(classInstanceAlignment, T))
8271
+ void [__traits(classInstanceSize, T)] buffer = void ;
8277
8272
8278
8273
@property inout (T) Scoped_payload() inout
8279
8274
{
8280
- void * alignedStore = cast (void * ) aligned(cast (size_t ) Scoped_store.ptr);
8281
- // As `Scoped` can be unaligned moved in memory class instance should be moved accordingly.
8282
- immutable size_t d = alignedStore - Scoped_store.ptr;
8283
- size_t * currD = cast (size_t * ) &Scoped_store[$ - size_t .sizeof];
8284
- if (d != * currD)
8285
- {
8286
- import core.stdc.string : memmove;
8287
- memmove(alignedStore, Scoped_store.ptr + * currD, __traits(classInstanceSize, T));
8288
- * currD = d;
8289
- }
8290
- return cast (inout (T)) alignedStore;
8275
+ return cast (inout (T)) buffer.ptr;
8291
8276
}
8292
8277
alias Scoped_payload this ;
8293
8278
@@ -8296,9 +8281,7 @@ if (is(T == class))
8296
8281
8297
8282
~this ()
8298
8283
{
8299
- // `destroy` will also write .init but we have no functions in druntime
8300
- // for deterministic finalization and memory releasing for now.
8301
- .destroy (Scoped_payload);
8284
+ .destroy ! false (Scoped_payload);
8302
8285
}
8303
8286
}
8304
8287
@@ -8310,10 +8293,7 @@ if (is(T == class))
8310
8293
import core.lifetime : emplace, forward;
8311
8294
8312
8295
Scoped result = void ;
8313
- void * alignedStore = cast (void * ) aligned(cast (size_t ) result.Scoped_store.ptr);
8314
- immutable size_t d = alignedStore - result.Scoped_store.ptr;
8315
- * cast (size_t * ) &result.Scoped_store[$ - size_t .sizeof] = d;
8316
- emplace! (Unqual! T)(result.Scoped_store[d .. $ - size_t .sizeof], forward! args);
8296
+ emplace! (Unqual! T)(result.buffer, forward! args);
8317
8297
return result;
8318
8298
}
8319
8299
}
@@ -8400,13 +8380,6 @@ if (is(T == class))
8400
8380
destroy (* b2); // calls A's destructor for b2.a
8401
8381
}
8402
8382
8403
- private size_t _alignUp (size_t alignment)(size_t n)
8404
- if (alignment > 0 && ! ((alignment - 1 ) & alignment))
8405
- {
8406
- enum badEnd = alignment - 1 ; // 0b11, 0b111, ...
8407
- return (n + badEnd) & ~ badEnd;
8408
- }
8409
-
8410
8383
// https://issues.dlang.org/show_bug.cgi?id=6580 testcase
8411
8384
@system unittest
8412
8385
{
0 commit comments