Skip to content

Commit 8813f1d

Browse files
committed
erts: Cleanup erts_reserve_heap__
Less fancy interleaved case and if
1 parent 90303aa commit 8813f1d

1 file changed

Lines changed: 49 additions & 51 deletions

File tree

erts/emulator/beam/erl_message.c

Lines changed: 49 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1377,6 +1377,8 @@ void erts_reserve_heap__(ErtsHeapFactory* factory, Uint need, Uint xtra)
13771377
{
13781378
/* internal... */
13791379
ErlHeapFragment* bp;
1380+
int replace_oh;
1381+
int replace_msg_hfrag;
13801382

13811383
switch (factory->mode) {
13821384
case FACTORY_HALLOC:
@@ -1385,65 +1387,61 @@ void erts_reserve_heap__(ErtsHeapFactory* factory, Uint need, Uint xtra)
13851387
factory->hp_end = factory->hp + need;
13861388
return;
13871389

1388-
case FACTORY_MESSAGE: {
1389-
int replace_oh;
1390-
int replace_msg_hfrag;
1391-
if (!factory->heap_frags) {
1390+
case FACTORY_MESSAGE:
1391+
if (!factory->heap_frags) {
13921392
ASSERT(factory->message->data.attached == ERTS_MSG_COMBINED_HFRAG);
13931393
bp = &factory->message->hfrag;
1394+
break;
13941395
}
1395-
else {
1396-
/* Fall through */
1397-
case FACTORY_HEAP_FRAGS:
1398-
case FACTORY_TMP:
1399-
bp = factory->heap_frags;
1400-
}
1401-
1402-
replace_oh = 0;
1403-
replace_msg_hfrag = 0;
1404-
1405-
if (bp) {
1406-
ASSERT(factory->hp >= bp->mem);
1407-
ASSERT(factory->hp <= factory->hp_end);
1408-
ASSERT(factory->hp_end == bp->mem + bp->alloc_size);
1409-
1410-
bp->used_size = factory->hp - bp->mem;
1411-
if (!bp->used_size && factory->heap_frags) {
1412-
factory->heap_frags = bp->next;
1413-
bp->next = NULL;
1414-
ASSERT(!bp->off_heap.first);
1415-
if (factory->off_heap == &bp->off_heap)
1416-
replace_oh = !0;
1417-
if (factory->message && factory->message->data.heap_frag == bp)
1418-
replace_msg_hfrag = !0;
1419-
free_message_buffer(bp);
1420-
}
1421-
}
1422-
bp = (ErlHeapFragment*) ERTS_HEAP_ALLOC(factory->alloc_type,
1423-
ERTS_HEAP_FRAG_SIZE(need+xtra));
1424-
bp->next = factory->heap_frags;
1425-
factory->heap_frags = bp;
1426-
bp->alloc_size = need + xtra;
1427-
bp->used_size = need + xtra;
1428-
bp->off_heap.first = NULL;
1429-
bp->off_heap.overhead = 0;
1430-
if (replace_oh) {
1431-
factory->off_heap = &bp->off_heap;
1432-
factory->off_heap_saved.first = factory->off_heap->first;
1433-
factory->off_heap_saved.overhead = factory->off_heap->overhead;
1434-
}
1435-
if (replace_msg_hfrag)
1436-
factory->message->data.heap_frag = bp;
1437-
factory->hp = bp->mem;
1438-
factory->hp_end = bp->mem + bp->alloc_size;
1439-
return;
1440-
}
1396+
ERTS_FALLTHROUGH();
1397+
case FACTORY_HEAP_FRAGS:
1398+
case FACTORY_TMP:
1399+
bp = factory->heap_frags;
1400+
break;
14411401

14421402
case FACTORY_STATIC:
14431403
case FACTORY_CLOSED:
14441404
default:
1445-
ASSERT(!"Invalid factory mode");
1405+
erts_exit(ERTS_ABORT_EXIT, "Invalid factory mode %d\n", factory->mode);
1406+
}
1407+
1408+
replace_oh = 0;
1409+
replace_msg_hfrag = 0;
1410+
1411+
if (bp) {
1412+
ASSERT(factory->hp >= bp->mem);
1413+
ASSERT(factory->hp <= factory->hp_end);
1414+
ASSERT(factory->hp_end == bp->mem + bp->alloc_size);
1415+
1416+
bp->used_size = factory->hp - bp->mem;
1417+
if (!bp->used_size && factory->heap_frags) {
1418+
factory->heap_frags = bp->next;
1419+
bp->next = NULL;
1420+
ASSERT(!bp->off_heap.first);
1421+
if (factory->off_heap == &bp->off_heap)
1422+
replace_oh = !0;
1423+
if (factory->message && factory->message->data.heap_frag == bp)
1424+
replace_msg_hfrag = !0;
1425+
free_message_buffer(bp);
1426+
}
1427+
}
1428+
bp = (ErlHeapFragment*) ERTS_HEAP_ALLOC(factory->alloc_type,
1429+
ERTS_HEAP_FRAG_SIZE(need+xtra));
1430+
bp->next = factory->heap_frags;
1431+
factory->heap_frags = bp;
1432+
bp->alloc_size = need + xtra;
1433+
bp->used_size = need + xtra;
1434+
bp->off_heap.first = NULL;
1435+
bp->off_heap.overhead = 0;
1436+
if (replace_oh) {
1437+
factory->off_heap = &bp->off_heap;
1438+
factory->off_heap_saved.first = factory->off_heap->first;
1439+
factory->off_heap_saved.overhead = factory->off_heap->overhead;
14461440
}
1441+
if (replace_msg_hfrag)
1442+
factory->message->data.heap_frag = bp;
1443+
factory->hp = bp->mem;
1444+
factory->hp_end = bp->mem + bp->alloc_size;
14471445
}
14481446

14491447
void erts_factory_close(ErtsHeapFactory* factory)

0 commit comments

Comments
 (0)