@@ -12,6 +12,8 @@ composite allocators.
12
12
struct NullAllocator
13
13
{
14
14
import std.typecons : Ternary;
15
+
16
+ nothrow @nogc pure @safe :
15
17
/**
16
18
`NullAllocator` advertises a relatively large _alignment equal to 64 KB.
17
19
This is because `NullAllocator` never actually needs to honor this
@@ -33,65 +35,59 @@ struct NullAllocator
33
35
Precondition: $(D b is null). This is because there is no other possible
34
36
legitimate input.
35
37
*/
36
- pure nothrow @safe @nogc
37
38
bool expand (ref void [] b, size_t s) shared
38
39
{ assert (b is null ); return s == 0 ; }
39
40
// / Ditto
40
- pure nothrow @nogc
41
41
bool reallocate (ref void [] b, size_t ) shared
42
42
{ assert (b is null ); return false ; }
43
43
// / Ditto
44
- pure nothrow @nogc
45
44
bool alignedReallocate (ref void [] b, size_t , uint ) shared
46
45
{ assert (b is null ); return false ; }
47
46
// / Returns `Ternary.no`.
48
- pure nothrow @safe @nogc
49
47
Ternary owns (const void []) shared const { return Ternary.no; }
50
48
/**
51
49
Returns `Ternary.no`.
52
50
*/
53
- pure nothrow @safe @nogc
54
51
Ternary resolveInternalPointer (const void * , ref void []) shared const
55
52
{ return Ternary.no; }
56
53
/**
57
54
No-op.
58
55
Precondition: $(D b is null)
59
56
*/
60
- pure nothrow @nogc
61
57
bool deallocate (void [] b) shared { assert (b is null ); return true ; }
62
58
/**
63
59
No-op.
64
60
*/
65
- pure nothrow @safe @nogc
66
61
bool deallocateAll () shared { return true ; }
67
62
/**
68
63
Returns `Ternary.yes`.
69
64
*/
70
- pure nothrow @safe @nogc
71
65
Ternary empty () shared const { return Ternary.yes; }
72
66
/**
73
67
Returns the `shared` global instance of the `NullAllocator`.
74
68
*/
75
69
static shared NullAllocator instance;
76
70
}
77
71
78
- @system unittest
72
+ nothrow @nogc pure @safe unittest
79
73
{
80
- assert (NullAllocator.instance.alignedAllocate(100 , 0 ) is null );
81
- assert (NullAllocator.instance.allocateAll() is null );
82
- auto b = NullAllocator.instance.allocate(100 );
74
+ alias a = NullAllocator.instance;
75
+
76
+ assert (a.alignedAllocate(100 , 0 ) is null );
77
+ assert (a.allocateAll() is null );
78
+ auto b = a.allocate(100 );
83
79
assert (b is null );
84
- assert ((() nothrow @safe @nogc => NullAllocator.instance. expand(b, 0 ))( ));
85
- assert ((() nothrow @safe @nogc => ! NullAllocator.instance. expand(b, 42 ))( ));
86
- assert ((() nothrow @nogc => ! NullAllocator.instance. reallocate(b, 42 ))( ));
87
- assert ((() nothrow @nogc => ! NullAllocator.instance. alignedReallocate(b, 42 , 0 ))( ));
88
- assert ((() nothrow @nogc => NullAllocator.instance. deallocate(b))( ));
89
- assert ((() nothrow @nogc => NullAllocator.instance. deallocateAll()) ());
80
+ assert (a. expand(b, 0 ));
81
+ assert (! a. expand(b, 42 ));
82
+ assert (! a. reallocate(b, 42 ));
83
+ assert (! a. alignedReallocate(b, 42 , 0 ));
84
+ assert (a. deallocate(b));
85
+ assert (a. deallocateAll());
90
86
91
87
import std.typecons : Ternary;
92
- assert ((() nothrow @safe @nogc => NullAllocator.instance. empty)() == Ternary.yes);
93
- assert ((() nothrow @safe @nogc => NullAllocator.instance. owns(null ))( ) == Ternary.no);
88
+ assert (a. empty == Ternary.yes);
89
+ assert (a. owns(null ) == Ternary.no);
94
90
95
91
void [] p;
96
- assert ((() nothrow @safe @nogc => NullAllocator.instance. resolveInternalPointer(null , p))( ) == Ternary.no);
92
+ assert (a. resolveInternalPointer(null , p) == Ternary.no);
97
93
}
0 commit comments