From: Leandro Lucarella Date: Sun, 6 Sep 2009 20:26:03 +0000 (-0300) Subject: Compare pointers explicitly against null using is and !is X-Git-Tag: word-sized-cells~1 X-Git-Url: https://git.llucax.com/software/dgc/naive.git/commitdiff_plain/0b322656db5f4d5b505fa7841a206b43d1b85414?hp=346f04b3e1026ded5af3ac95a483b2c3d05a6d60 Compare pointers explicitly against null using is and !is --- diff --git a/gc/cell.d b/gc/cell.d index b8261de..cd8fae1 100644 --- a/gc/cell.d +++ b/gc/cell.d @@ -182,7 +182,7 @@ private: 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; diff --git a/gc/dynarray.d b/gc/dynarray.d index 9836258..bd387cf 100644 --- a/gc/dynarray.d +++ b/gc/dynarray.d @@ -153,19 +153,19 @@ private: 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++); @@ -173,19 +173,19 @@ private: 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"); } diff --git a/gc/gc.d b/gc/gc.d index dfe084b..a10143a 100644 --- a/gc/gc.d +++ b/gc/gc.d @@ -455,7 +455,7 @@ public: uint getAttr(void* ptr) { auto cell = this.live_list.find(ptr); - if (cell) + if (cell !is null) return cell.attr; return 0; } @@ -471,7 +471,7 @@ public: 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; @@ -490,7 +490,7 @@ public: 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; @@ -518,7 +518,7 @@ public: // 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 @@ -526,13 +526,13 @@ public: 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 @@ -592,7 +592,7 @@ public: } 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) { @@ -675,7 +675,7 @@ public: return; auto cell = this.live_list.pop(ptr); - assert (cell); + assert (cell !is null); this.free_list.link(cell); } @@ -696,7 +696,7 @@ public: } auto cell = this.live_list.find(&in_range); - if (cell) + if (cell !is null) return cell.ptr; return null; @@ -715,7 +715,7 @@ public: size_t sizeOf(void* ptr) { auto cell = this.live_list.find(ptr); - if (cell) + if (cell !is null) return cell.capacity; return 0; } @@ -734,7 +734,7 @@ public: 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; diff --git a/gc/list.d b/gc/list.d index 7c0af0b..f11ff2c 100644 --- a/gc/list.d +++ b/gc/list.d @@ -37,7 +37,7 @@ struct List Cell* find(bool delegate(Cell*) predicate) { auto cell = this.first; - while (cell) { + while (cell !is null) { if (predicate(cell)) return cell; cell = cell.next; @@ -75,12 +75,12 @@ struct List { 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; @@ -133,7 +133,7 @@ struct List { 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); @@ -156,7 +156,7 @@ private: 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;