@@ -8707,29 +8707,14 @@ are no pointers to it. As such, it is illegal to move a scoped object.
8707
8707
template scoped (T)
8708
8708
if (is (T == class ))
8709
8709
{
8710
- // _d_newclass now use default GC alignment (looks like (void*).sizeof * 2 for
8711
- // small objects). We will just use the maximum of filed alignments.
8712
- enum alignment = __traits(classInstanceAlignment, T);
8713
- alias aligned = _alignUp! alignment;
8714
-
8715
8710
static struct Scoped
8716
8711
{
8717
- // Addition of `alignment` is required as `Scoped_store` can be misaligned in memory.
8718
- private void [aligned( __traits(classInstanceSize, T) + size_t .sizeof) + alignment] Scoped_store = void ;
8712
+ private align (__traits(classInstanceAlignment, T))
8713
+ void [__traits(classInstanceSize, T)] buffer = void ;
8719
8714
8720
8715
@property inout (T) Scoped_payload() inout
8721
8716
{
8722
- void * alignedStore = cast (void * ) aligned(cast (size_t ) Scoped_store.ptr);
8723
- // As `Scoped` can be unaligned moved in memory class instance should be moved accordingly.
8724
- immutable size_t d = alignedStore - Scoped_store.ptr;
8725
- size_t * currD = cast (size_t * ) &Scoped_store[$ - size_t .sizeof];
8726
- if (d != * currD)
8727
- {
8728
- import core.stdc.string : memmove;
8729
- memmove(alignedStore, Scoped_store.ptr + * currD, __traits(classInstanceSize, T));
8730
- * currD = d;
8731
- }
8732
- return cast (inout (T)) alignedStore;
8717
+ return cast (inout (T)) buffer.ptr;
8733
8718
}
8734
8719
alias Scoped_payload this ;
8735
8720
@@ -8738,9 +8723,7 @@ if (is(T == class))
8738
8723
8739
8724
~this ()
8740
8725
{
8741
- // `destroy` will also write .init but we have no functions in druntime
8742
- // for deterministic finalization and memory releasing for now.
8743
- .destroy (Scoped_payload);
8726
+ .destroy ! false (Scoped_payload);
8744
8727
}
8745
8728
}
8746
8729
@@ -8752,10 +8735,7 @@ if (is(T == class))
8752
8735
import core.lifetime : emplace, forward;
8753
8736
8754
8737
Scoped result = void ;
8755
- void * alignedStore = cast (void * ) aligned(cast (size_t ) result.Scoped_store.ptr);
8756
- immutable size_t d = alignedStore - result.Scoped_store.ptr;
8757
- * cast (size_t * ) &result.Scoped_store[$ - size_t .sizeof] = d;
8758
- emplace! (Unqual! T)(result.Scoped_store[d .. $ - size_t .sizeof], forward! args);
8738
+ emplace! (Unqual! T)(result.buffer, forward! args);
8759
8739
return result;
8760
8740
}
8761
8741
}
@@ -8842,13 +8822,6 @@ if (is(T == class))
8842
8822
destroy (* b2); // calls A's destructor for b2.a
8843
8823
}
8844
8824
8845
- private size_t _alignUp (size_t alignment)(size_t n)
8846
- if (alignment > 0 && ! ((alignment - 1 ) & alignment))
8847
- {
8848
- enum badEnd = alignment - 1 ; // 0b11, 0b111, ...
8849
- return (n + badEnd) & ~ badEnd;
8850
- }
8851
-
8852
8825
// https://issues.dlang.org/show_bug.cgi?id=6580 testcase
8853
8826
@system unittest
8854
8827
{
0 commit comments