@@ -1170,7 +1170,10 @@ auto make(T, Allocator, A...)(auto ref Allocator alloc, auto ref A args)
1170
1170
import std.algorithm.comparison : max;
1171
1171
static if (! is (T == class ) && ! is (T == interface ) && A.length == 0
1172
1172
&& __traits(compiles, {T t;}) && __traits(isZeroInit, T)
1173
- && is (typeof (alloc.allocateZeroed(size_t .max))))
1173
+ && is (typeof (alloc.allocateZeroed(size_t .max)))
1174
+ && (! is (typeof (alloc.alignedAllocate(size_t .max, uint .max))) ||
1175
+ ( is (typeof (alloc.alignedAllocate(size_t .max, uint .max))) && Allocator.alignment == T.alignof)
1176
+ ))
1174
1177
{
1175
1178
auto m = alloc.allocateZeroed(max(T.sizeof, 1 ));
1176
1179
return (() @trusted => cast (T* ) m.ptr)();
@@ -1180,7 +1183,22 @@ auto make(T, Allocator, A...)(auto ref Allocator alloc, auto ref A args)
1180
1183
import core.internal.lifetime : emplaceRef;
1181
1184
import core.lifetime : emplace;
1182
1185
1183
- auto m = alloc.allocate(max(stateSize! T, 1 ));
1186
+ static if (is (typeof (alloc.alignedAllocate(size_t .max, uint .max))))
1187
+ {
1188
+ static if (is (T == class ))
1189
+ {
1190
+ import std.traits : classInstanceAlignment;
1191
+ auto m = alloc.alignedAllocate(max(stateSize! T, 1 ), classInstanceAlignment! T);
1192
+ }
1193
+ else
1194
+ {
1195
+ auto m = alloc.alignedAllocate(max(stateSize! T, 1 ), T.alignof);
1196
+ }
1197
+ }
1198
+ else
1199
+ {
1200
+ auto m = alloc.allocate(max(stateSize! T, 1 ));
1201
+ }
1184
1202
if (! m.ptr) return null ;
1185
1203
1186
1204
// make can only be @safe if emplace or emplaceRef is `pure`
@@ -1593,14 +1611,20 @@ T[] makeArray(T, Allocator)(auto ref Allocator alloc, size_t length)
1593
1611
if (overflow) return null ;
1594
1612
}
1595
1613
1596
- static if (__traits(isZeroInit, T) && hasMember! (Allocator, " allocateZeroed" ))
1614
+ static if (__traits(isZeroInit, T)
1615
+ && hasMember! (Allocator, " allocateZeroed" )
1616
+ && ! hasMember! (Allocator, " alignedAllocate" )
1617
+ )
1597
1618
{
1598
1619
auto m = alloc.allocateZeroed(nAlloc);
1599
1620
return (() @trusted => cast (T[]) m)();
1600
1621
}
1601
1622
else
1602
1623
{
1603
- auto m = alloc.allocate(nAlloc);
1624
+ static if (hasMember! (Allocator, " alignedAllocate" ))
1625
+ auto m = alloc.alignedAllocate(nAlloc, T.alignof);
1626
+ else
1627
+ auto m = alloc.allocate(nAlloc);
1604
1628
if (! m.ptr) return null ;
1605
1629
alias U = Unqual! T;
1606
1630
return () @trusted { return cast (T[]) uninitializedFillDefault(cast (U[]) m); }();
0 commit comments