Skip to content

Commit 7986102

Browse files
committed
Replace IAllocator with reference counted struct
1 parent b5cdcc9 commit 7986102

3 files changed

Lines changed: 558 additions & 58 deletions

File tree

std/experimental/allocator/building_blocks/affix_allocator.d

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ struct AffixAllocator(Allocator, Prefix, Suffix = void)
2121
{
2222
import std.algorithm.comparison : min;
2323
import std.conv : emplace;
24-
import std.experimental.allocator : IAllocator, theAllocator;
24+
import std.experimental.allocator : RCIAllocator, theAllocator;
2525
import std.experimental.allocator.common : stateSize, forwardToMember,
2626
roundUpToMultipleOf, alignedAt, alignDownTo, roundUpToMultipleOf,
2727
hasStaticallyKnownAlignment;
@@ -66,11 +66,11 @@ struct AffixAllocator(Allocator, Prefix, Suffix = void)
6666
static if (stateSize!Allocator)
6767
{
6868
Allocator _parent;
69-
static if (is(Allocator == IAllocator))
69+
static if (is(Allocator == RCIAllocator))
7070
{
7171
Allocator parent()
7272
{
73-
if (_parent is null) _parent = theAllocator;
73+
if (_parent.isNull) _parent = theAllocator;
7474
assert(alignment <= _parent.alignment);
7575
return _parent;
7676
}
@@ -373,18 +373,18 @@ struct AffixAllocator(Allocator, Prefix, Suffix = void)
373373
@system unittest
374374
{
375375
import std.experimental.allocator.gc_allocator : GCAllocator;
376-
import std.experimental.allocator : theAllocator, IAllocator;
376+
import std.experimental.allocator : theAllocator, RCIAllocator;
377377

378378
// One word before and after each allocation.
379-
auto A = AffixAllocator!(IAllocator, size_t, size_t)(theAllocator);
379+
auto A = AffixAllocator!(RCIAllocator, size_t, size_t)(theAllocator);
380380
auto a = A.allocate(11);
381381
A.prefix(a) = 0xCAFE_BABE;
382382
A.suffix(a) = 0xDEAD_BEEF;
383383
assert(A.prefix(a) == 0xCAFE_BABE
384384
&& A.suffix(a) == 0xDEAD_BEEF);
385385

386386
// One word before and after each allocation.
387-
auto B = AffixAllocator!(IAllocator, size_t, size_t)();
387+
auto B = AffixAllocator!(RCIAllocator, size_t, size_t)();
388388
auto b = B.allocate(11);
389389
B.prefix(b) = 0xCAFE_BABE;
390390
B.suffix(b) = 0xDEAD_BEEF;

std/experimental/allocator/common.d

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,7 @@ Forwards each of the methods in `funs` (if defined) to `member`.
478478

479479
version(unittest)
480480
{
481-
import std.experimental.allocator : IAllocator, ISharedAllocator;
481+
import std.experimental.allocator : RCIAllocator, RCISharedAllocator;
482482

483483
package void testAllocator(alias make)()
484484
{
@@ -604,18 +604,18 @@ version(unittest)
604604
}}
605605
}
606606

607-
package void testAllocatorObject(AllocInterface)(AllocInterface a)
608-
if (is(AllocInterface : IAllocator)
609-
|| is (AllocInterface : shared ISharedAllocator))
607+
package void testAllocatorObject(RCAllocInterface)(RCAllocInterface a)
608+
if (is(RCAllocInterface == RCIAllocator)
609+
|| is (RCAllocInterface == shared RCISharedAllocator))
610610
{
611611
import std.conv : text;
612612
import std.math : isPowerOf2;
613613
import std.stdio : writeln, stderr;
614614
import std.typecons : Ternary;
615615
scope(failure) stderr.writeln("testAllocatorObject failed for ",
616-
AllocInterface.stringof);
616+
RCAllocInterface.stringof);
617617

618-
assert(a);
618+
assert(!a.isNull);
619619

620620
// Test alignment
621621
assert(a.alignment.isPowerOf2);

0 commit comments

Comments
 (0)