From: Leandro Lucarella Date: Tue, 22 Jun 2010 03:39:50 +0000 (-0300) Subject: Comment why we avoid calling free with null X-Git-Url: https://git.llucax.com/software/dgc/cdgc.git/commitdiff_plain/d512e824a57ab7912ce0c57798a8560479637c10?ds=inline;hp=5b9125d77fe31ab9bc0b772db804b0fa9fd81982 Comment why we avoid calling free with null Even when free() can be called with a null pointer, the extra call might be significant. On hard GC benchmarks making the test for null in the GC code (i.e. avoiding the free() call) can reduce the GC time by almost ~5%. --- diff --git a/rt/gc/cdgc/bits.d b/rt/gc/cdgc/bits.d index 02300ce..4d25362 100644 --- a/rt/gc/cdgc/bits.d +++ b/rt/gc/cdgc/bits.d @@ -62,6 +62,10 @@ struct GCBits void Dtor() { + // Even when free() can be called with a null pointer, the extra call + // might be significant. On hard GC benchmarks making the test for null + // here (i.e. not making the call) can reduce the GC time by almost + // ~5%. if (data) { cstdlib.free(data); diff --git a/rt/gc/cdgc/gc.d b/rt/gc/cdgc/gc.d index ee05d60..1e95f06 100644 --- a/rt/gc/cdgc/gc.d +++ b/rt/gc/cdgc/gc.d @@ -1378,12 +1378,15 @@ struct Gcx pool.Dtor(); cstdlib.free(pool); } + + // Even when free() can be called with a null pointer, the extra call + // might be significant. On hard GC benchmarks making the test for null + // here (i.e. not making the call) can reduce the GC time by almost + // ~5%. if (pooltable) cstdlib.free(pooltable); - if (roots) cstdlib.free(roots); - if (ranges) cstdlib.free(ranges); } @@ -2579,6 +2582,7 @@ struct Pool baseAddr = null; topAddr = null; } + // See Gcx.Dtor() for the rationale of the null check. if (pagetable) cstdlib.free(pagetable);