auto N = 10;
auto size = N * size_t.sizeof;
auto cell = Cell.alloc(size, BlkAttr.FINALIZE | BlkAttr.NO_SCAN);
- assert (cell);
+ assert (cell !is null);
assert (cell.ptr is cell + 1);
for (int i = 0; i < N; ++i) {
auto ptr = cast(size_t*) cell.ptr + i;
DynArray!(int) array;
assert (array.size == 0);
assert (array.capacity == 0);
- assert (array.data == null);
+ assert (array.data is null);
foreach (x; array)
assert (false, "there should be no elements in the array");
array.append(5);
assert (array.size == 1);
assert (array.capacity >= 1);
- assert (array.data);
+ assert (array.data !is null);
foreach (x; array)
assert (x == 5);
array.append(6);
assert (array.size == 2);
assert (array.capacity >= 2);
- assert (array.data);
+ assert (array.data !is null);
int i = 0;
foreach (x; array)
assert (x == 5 + i++);
array.remove(5);
assert (array.size == 1);
assert (array.capacity >= 1);
- assert (array.data);
+ assert (array.data !is null);
foreach (x; array)
assert (x == 6);
array.expand(100);
assert (array.size == 1);
assert (array.capacity >= 100);
- assert (array.data);
+ assert (array.data !is null);
foreach (x; array)
assert (x == 6);
array.clear();
assert (array.size == 0);
assert (array.capacity == 0);
- assert (array.data == null);
+ assert (array.data is null);
foreach (x; array)
assert (false, "there should be no elements in the array");
}
uint getAttr(void* ptr)
{
auto cell = this.live_list.find(ptr);
- if (cell)
+ if (cell !is null)
return cell.attr;
return 0;
}
uint setAttr(void* ptr, uint attr)
{
auto cell = this.live_list.find(ptr);
- if (cell) {
+ if (cell !is null) {
auto old = cell.attr;
cell.attr |= attr;
return cell.attr;
uint clrAttr(void* ptr, uint attr)
{
auto cell = this.live_list.find(ptr);
- if (cell) {
+ if (cell !is null) {
auto old = cell.attr;
cell.attr &= ~attr;
return cell.attr;
// Find a free cell in the free list with enough space
auto cell = this.free_list.pop(size);
- if (cell)
+ if (cell !is null)
goto reuse;
// No room in the free list found, if the GC is enabled, trigger
if (!this.disabled) {
this.collect();
cell = this.free_list.pop(size);
- if (cell)
+ if (cell !is null)
goto reuse;
}
// No luck still, allocate a new cell
cell = Cell.alloc(size, attr);
- if (cell)
+ if (cell !is null)
goto link;
// No memory
}
auto cell = this.live_list.find(ptr);
- assert (cell);
+ assert (cell !is null);
// We have enough capacity already, just change the size
if (cell.capacity >= size) {
return;
auto cell = this.live_list.pop(ptr);
- assert (cell);
+ assert (cell !is null);
this.free_list.link(cell);
}
}
auto cell = this.live_list.find(&in_range);
- if (cell)
+ if (cell !is null)
return cell.ptr;
return null;
size_t sizeOf(void* ptr)
{
auto cell = this.live_list.find(ptr);
- if (cell)
+ if (cell !is null)
return cell.capacity;
return 0;
}
BlkInfo blk_info;
auto cell = this.live_list.find(ptr);
- if (cell) {
+ if (cell !is null) {
blk_info.base = cell.ptr;
blk_info.size = cell.capacity;
blk_info.attr = cell.attr;
Cell* find(bool delegate(Cell*) predicate)
{
auto cell = this.first;
- while (cell) {
+ while (cell !is null) {
if (predicate(cell))
return cell;
cell = cell.next;
{
Cell* prev = null;
auto cell = this.first;
- while (cell) {
+ while (cell !is null) {
if (predicate(cell)) {
- if (prev)
- prev.next = cell.next;
- else
+ if (prev is null)
this.first = cell.next;
+ else
+ prev.next = cell.next;
return cell;
}
prev = cell;
{
int result = 0;
auto cell = this.first;
- while (cell) {
+ while (cell !is null) {
// this is necessary to allow removing a node while iterating
auto next = cell.next;
result = dg(cell);
unittest // List
{
List l;
- assert (l.first == null);
+ assert (l.first is null);
assert (l.find(cast(void*) null) is null);
assert (l.find(cast(void*) &l) is null);
Cell[5] cells;