MCPcopy Create free account
hub / github.com/emscripten-core/emscripten / tmalloc_small

Function tmalloc_small

system/lib/dlmalloc.c:4591–4626  ·  view source on GitHub ↗

allocate a small request from the best fitting chunk in a treebin */

Source from the content-addressed store, hash-verified

4589
4590/* allocate a small request from the best fitting chunk in a treebin */
4591static void* tmalloc_small(mstate m, size_t nb) {
4592 tchunkptr t, v;
4593 size_t rsize;
4594 bindex_t i;
4595 binmap_t leastbit = least_bit(m->treemap);
4596 compute_bit2idx(leastbit, i);
4597 v = t = *treebin_at(m, i);
4598 rsize = chunksize(t) - nb;
4599
4600 while ((t = leftmost_child(t)) != 0) {
4601 size_t trem = chunksize(t) - nb;
4602 if (trem < rsize) {
4603 rsize = trem;
4604 v = t;
4605 }
4606 }
4607
4608 if (RTCHECK(ok_address(m, v))) {
4609 mchunkptr r = chunk_plus_offset(v, nb);
4610 assert(chunksize(v) == rsize + nb);
4611 if (RTCHECK(ok_next(v, r))) {
4612 unlink_large_chunk(m, v);
4613 if (rsize < MIN_CHUNK_SIZE)
4614 set_inuse_and_pinuse(m, v, (rsize + nb));
4615 else {
4616 set_size_and_pinuse_of_inuse_chunk(m, v, nb);
4617 set_size_and_pinuse_of_free_chunk(r, rsize);
4618 replace_dv(m, r, rsize);
4619 }
4620 return chunk2mem(v);
4621 }
4622 }
4623
4624 CORRUPTION_ERROR_ACTION(m);
4625 return 0;
4626}
4627
4628#if !ONLY_MSPACES
4629

Callers 2

dlmallocFunction · 0.85
mspace_mallocFunction · 0.85

Calls 1

assertFunction · 0.50

Tested by

no test coverage detected