allocate a large request from the best fitting chunk in a treebin */
| 3859 | |
| 3860 | /* allocate a large request from the best fitting chunk in a treebin */ |
| 3861 | static void* tmalloc_large(mstate m, size_t nb) { |
| 3862 | tchunkptr v = 0; |
| 3863 | size_t rsize = -nb; /* Unsigned negation */ |
| 3864 | tchunkptr t; |
| 3865 | bindex_t idx; |
| 3866 | compute_tree_index(nb, idx); |
| 3867 | |
| 3868 | if ((t = *treebin_at(m, idx)) != 0) { |
| 3869 | /* Traverse tree for this bin looking for node with size == nb */ |
| 3870 | size_t sizebits = nb << leftshift_for_tree_index(idx); |
| 3871 | tchunkptr rst = 0; /* The deepest untaken right subtree */ |
| 3872 | for (;;) { |
| 3873 | tchunkptr rt; |
| 3874 | size_t trem = chunksize(t) - nb; |
| 3875 | if (trem < rsize) { |
| 3876 | v = t; |
| 3877 | if ((rsize = trem) == 0) |
| 3878 | break; |
| 3879 | } |
| 3880 | rt = t->child[1]; |
| 3881 | t = t->child[(sizebits >> (SIZE_T_BITSIZE-SIZE_T_ONE)) & 1]; |
| 3882 | if (rt != 0 && rt != t) |
| 3883 | rst = rt; |
| 3884 | if (t == 0) { |
| 3885 | t = rst; /* set t to least subtree holding sizes > nb */ |
| 3886 | break; |
| 3887 | } |
| 3888 | sizebits <<= 1; |
| 3889 | } |
| 3890 | } |
| 3891 | |
| 3892 | if (t == 0 && v == 0) { /* set t to root of next non-empty treebin */ |
| 3893 | binmap_t leftbits = left_bits(idx2bit(idx)) & m->treemap; |
| 3894 | if (leftbits != 0) { |
| 3895 | bindex_t i; |
| 3896 | binmap_t leastbit = least_bit(leftbits); |
| 3897 | compute_bit2idx(leastbit, i); |
| 3898 | t = *treebin_at(m, i); |
| 3899 | } |
| 3900 | } |
| 3901 | |
| 3902 | while (t != 0) { /* find smallest of tree or subtree */ |
| 3903 | size_t trem = chunksize(t) - nb; |
| 3904 | if (trem < rsize) { |
| 3905 | rsize = trem; |
| 3906 | v = t; |
| 3907 | } |
| 3908 | t = leftmost_child(t); |
| 3909 | } |
| 3910 | |
| 3911 | /* If dv is a better fit, return 0 so malloc will use it */ |
| 3912 | if (v != 0 && rsize < (size_t)(m->dvsize - nb)) { |
| 3913 | if (RTCHECK(ok_address(m, v))) { /* split */ |
| 3914 | mchunkptr r = chunk_plus_offset(v, nb); |
| 3915 | assert(chunksize(v) == rsize + nb); |
| 3916 | if (RTCHECK(ok_next(v, r))) { |
| 3917 | unlink_large_chunk(m, v); |
| 3918 | if (rsize < MIN_CHUNK_SIZE) |
no outgoing calls
no test coverage detected