@@ -9242,29 +9242,14 @@ are no pointers to it. As such, it is illegal to move a scoped object.
9242
9242
template scoped (T)
9243
9243
if (is (T == class ))
9244
9244
{
9245
- // _d_newclass now use default GC alignment (looks like (void*).sizeof * 2 for
9246
- // small objects). We will just use the maximum of filed alignments.
9247
- enum alignment = __traits(classInstanceAlignment, T);
9248
- alias aligned = _alignUp! alignment;
9249
-
9250
9245
static struct Scoped
9251
9246
{
9252
- // Addition of `alignment` is required as `Scoped_store` can be misaligned in memory.
9253
- private void [aligned( __traits(classInstanceSize, T) + size_t .sizeof) + alignment] Scoped_store = void ;
9247
+ private align (__traits(classInstanceAlignment, T))
9248
+ void [__traits(classInstanceSize, T)] buffer = void ;
9254
9249
9255
9250
@property inout (T) Scoped_payload() inout
9256
9251
{
9257
- void * alignedStore = cast (void * ) aligned(cast (size_t ) Scoped_store.ptr);
9258
- // As `Scoped` can be unaligned moved in memory class instance should be moved accordingly.
9259
- immutable size_t d = alignedStore - Scoped_store.ptr;
9260
- size_t * currD = cast (size_t * ) &Scoped_store[$ - size_t .sizeof];
9261
- if (d != * currD)
9262
- {
9263
- import core.stdc.string : memmove;
9264
- memmove(alignedStore, Scoped_store.ptr + * currD, __traits(classInstanceSize, T));
9265
- * currD = d;
9266
- }
9267
- return cast (inout (T)) alignedStore;
9252
+ return cast (inout (T)) buffer.ptr;
9268
9253
}
9269
9254
alias Scoped_payload this ;
9270
9255
@@ -9273,9 +9258,7 @@ if (is(T == class))
9273
9258
9274
9259
~this ()
9275
9260
{
9276
- // `destroy` will also write .init but we have no functions in druntime
9277
- // for deterministic finalization and memory releasing for now.
9278
- .destroy (Scoped_payload);
9261
+ .destroy ! false (Scoped_payload);
9279
9262
}
9280
9263
}
9281
9264
@@ -9287,10 +9270,7 @@ if (is(T == class))
9287
9270
import core.lifetime : emplace, forward;
9288
9271
9289
9272
Scoped result = void ;
9290
- void * alignedStore = cast (void * ) aligned(cast (size_t ) result.Scoped_store.ptr);
9291
- immutable size_t d = alignedStore - result.Scoped_store.ptr;
9292
- * cast (size_t * ) &result.Scoped_store[$ - size_t .sizeof] = d;
9293
- emplace! (Unqual! T)(result.Scoped_store[d .. $ - size_t .sizeof], forward! args);
9273
+ emplace! (Unqual! T)(result.buffer, forward! args);
9294
9274
return result;
9295
9275
}
9296
9276
}
@@ -9377,13 +9357,6 @@ if (is(T == class))
9377
9357
destroy (* b2); // calls A's destructor for b2.a
9378
9358
}
9379
9359
9380
- private size_t _alignUp (size_t alignment)(size_t n)
9381
- if (alignment > 0 && ! ((alignment - 1 ) & alignment))
9382
- {
9383
- enum badEnd = alignment - 1 ; // 0b11, 0b111, ...
9384
- return (n + badEnd) & ~ badEnd;
9385
- }
9386
-
9387
9360
// https://issues.dlang.org/show_bug.cgi?id=6580 testcase
9388
9361
@system unittest
9389
9362
{
0 commit comments