Skip to content
This repository was archived by the owner on Oct 12, 2022. It is now read-only.

Commit 1a232a4

Browse files
Geod24thewilsonator
authored andcommitted
GC: Remove trivial function npools and use opSlice
There is already a length (and opDollar) function in PoolTable, and npools had no attributes. Instead of adding the correct attributes, we can simply eliminate it and take advantage of opSlice, simplifying the code.
1 parent 25df7fd commit 1a232a4

File tree

1 file changed

+18
-21
lines changed
  • src/core/internal/gc/impl/conservative

1 file changed

+18
-21
lines changed

src/core/internal/gc/impl/conservative/gc.d

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1335,7 +1335,7 @@ class ConservativeGC : GC
13351335
//
13361336
private void getStatsNoSync(out core.memory.GC.Stats stats) nothrow
13371337
{
1338-
foreach (pool; gcx.pooltable[0 .. gcx.npools])
1338+
foreach (pool; gcx.pooltable[])
13391339
{
13401340
foreach (bin; pool.pagetable[0 .. pool.npages])
13411341
{
@@ -1353,7 +1353,7 @@ class ConservativeGC : GC
13531353
for (List *list = gcx.bucket[n]; list; list = list.next)
13541354
freeListSize += sz;
13551355

1356-
foreach (pool; gcx.pooltable[0 .. gcx.npools])
1356+
foreach (pool; gcx.pooltable[])
13571357
{
13581358
if (pool.isLargeObject)
13591359
continue;
@@ -1491,7 +1491,6 @@ struct Gcx
14911491
debug(INVARIANT) bool inCollection;
14921492
uint disabled; // turn off collections if >0
14931493

1494-
private @property size_t npools() pure const nothrow { return pooltable.length; }
14951494
PoolTable!Pool pooltable;
14961495

14971496
List*[B_NUMSMALL] bucket; // free list for each small size
@@ -1591,9 +1590,8 @@ struct Gcx
15911590

15921591
debug(INVARIANT) initialized = false;
15931592

1594-
for (size_t i = 0; i < npools; i++)
1593+
foreach (Pool* pool; this.pooltable[])
15951594
{
1596-
Pool *pool = pooltable[i];
15971595
mappedPages -= pool.npages;
15981596
pool.Dtor();
15991597
cstdlib.free(pool);
@@ -1751,7 +1749,7 @@ struct Gcx
17511749
ConservativeGC._inFinalizer = true;
17521750
scope (failure) ConservativeGC._inFinalizer = false;
17531751

1754-
foreach (pool; pooltable[0 .. npools])
1752+
foreach (pool; this.pooltable[])
17551753
{
17561754
if (!pool.finals.nbits) continue;
17571755

@@ -1993,7 +1991,7 @@ struct Gcx
19931991

19941992
bool tryAlloc() nothrow
19951993
{
1996-
foreach (p; pooltable[0 .. npools])
1994+
foreach (p; this.pooltable[])
19971995
{
19981996
if (!p.isLargeObject || p.freepages < npages)
19991997
continue;
@@ -2093,10 +2091,11 @@ struct Gcx
20932091
}
20942092

20952093
// Allocate successively larger pools up to 8 megs
2096-
if (npools)
2097-
{ size_t n;
2094+
if (this.pooltable.length)
2095+
{
2096+
size_t n;
20982097

2099-
n = config.minPoolSize + config.incPoolSize * npools;
2098+
n = config.minPoolSize + config.incPoolSize * this.pooltable.length;
21002099
if (n > config.maxPoolSize)
21012100
n = config.maxPoolSize; // cap pool size
21022101
n /= PAGESIZE; // convert bytes to pages
@@ -2138,9 +2137,8 @@ struct Gcx
21382137
List* allocPage(Bins bin) nothrow
21392138
{
21402139
//debug(PRINTF) printf("Gcx::allocPage(bin = %d)\n", bin);
2141-
for (size_t n = 0; n < npools; n++)
2140+
foreach (Pool* pool; this.pooltable[])
21422141
{
2143-
Pool* pool = pooltable[n];
21442142
if (pool.isLargeObject)
21452143
continue;
21462144
if (List* p = (cast(SmallObjectPool*)pool).allocPage(bin))
@@ -2274,7 +2272,7 @@ struct Gcx
22742272

22752273
// let dmd allocate a register for this.pools
22762274
auto pools = pooltable.pools;
2277-
const highpool = pooltable.npools - 1;
2275+
const highpool = pooltable.length - 1;
22782276
const minAddr = pooltable.minAddr;
22792277
size_t memSize = pooltable.maxAddr - minAddr;
22802278
Pool* pool = null;
@@ -2524,9 +2522,8 @@ struct Gcx
25242522
{
25252523
debug(COLLECT_PRINTF) printf("preparing mark.\n");
25262524

2527-
for (size_t n = 0; n < npools; n++)
2525+
foreach (Pool* pool; this.pooltable[])
25282526
{
2529-
Pool* pool = pooltable[n];
25302527
if (pool.isLargeObject)
25312528
pool.mark.zero();
25322529
else
@@ -2596,10 +2593,9 @@ struct Gcx
25962593
size_t freedLargePages;
25972594
size_t freedSmallPages;
25982595
size_t freed;
2599-
for (size_t n = 0; n < npools; n++)
2596+
foreach (Pool* pool; this.pooltable[])
26002597
{
26012598
size_t pn;
2602-
Pool* pool = pooltable[n];
26032599

26042600
if (pool.isLargeObject)
26052601
{
@@ -2787,7 +2783,8 @@ struct Gcx
27872783

27882784
assert(freedLargePages <= usedLargePages);
27892785
usedLargePages -= freedLargePages;
2790-
debug(COLLECT_PRINTF) printf("\tfree'd %u bytes, %u pages from %u pools\n", freed, freedLargePages, npools);
2786+
debug(COLLECT_PRINTF) printf("\tfree'd %u bytes, %u pages from %u pools\n",
2787+
freed, freedLargePages, this.pooltable.length);
27912788

27922789
assert(freedSmallPages <= usedSmallPages);
27932790
usedSmallPages -= freedSmallPages;
@@ -2852,12 +2849,12 @@ struct Gcx
28522849
private SmallObjectPool* setNextRecoverPool(Bins bin, size_t poolIndex) nothrow
28532850
{
28542851
Pool* pool;
2855-
while (poolIndex < npools &&
2856-
((pool = pooltable[poolIndex]).isLargeObject ||
2852+
while (poolIndex < this.pooltable.length &&
2853+
((pool = this.pooltable[poolIndex]).isLargeObject ||
28572854
pool.recoverPageFirst[bin] >= pool.npages))
28582855
poolIndex++;
28592856

2860-
return recoverPool[bin] = poolIndex < npools ? cast(SmallObjectPool*)pool : null;
2857+
return recoverPool[bin] = poolIndex < this.pooltable.length ? cast(SmallObjectPool*)pool : null;
28612858
}
28622859

28632860
version (COLLECT_FORK)

0 commit comments

Comments
 (0)