mirror of
https://github.com/ilyakooo0/urbit.git
synced 2024-12-15 01:52:42 +03:00
u3: adds u3a_wtrim(), for shrinking word-aligned allocations
This commit is contained in:
parent
4ce4ce1974
commit
012991310b
@ -429,6 +429,11 @@
|
||||
void
|
||||
u3a_wfree(void* lag_v);
|
||||
|
||||
/* u3a_wtrim(): trim storage.
|
||||
*/
|
||||
void
|
||||
u3a_wtrim(void* tox_v, c3_w old_w, c3_w len_w);
|
||||
|
||||
/* u3a_wealloc(): word realloc.
|
||||
*/
|
||||
void*
|
||||
|
@ -632,6 +632,28 @@ u3a_wfree(void* tox_v)
|
||||
_box_free(u3a_botox(tox_v));
|
||||
}
|
||||
|
||||
/* u3a_wtrim(): trim storage.
|
||||
*/
|
||||
void
|
||||
u3a_wtrim(void* tox_v, c3_w old_w, c3_w len_w)
|
||||
{
|
||||
c3_w* nov_w = tox_v;
|
||||
|
||||
if ( (old_w > len_w)
|
||||
&& ((old_w - len_w) >= u3a_minimum) )
|
||||
{
|
||||
c3_w* box_w = (void *)u3a_botox(nov_w);
|
||||
c3_w* end_w = (nov_w + len_w + 1);
|
||||
c3_w asz_w = (end_w - box_w);
|
||||
c3_w bsz_w = box_w[0] - asz_w;
|
||||
|
||||
_box_attach(_box_make(end_w, bsz_w, 0));
|
||||
|
||||
box_w[0] = asz_w;
|
||||
box_w[asz_w - 1] = asz_w;
|
||||
}
|
||||
}
|
||||
|
||||
/* u3a_calloc(): allocate and zero-initialize array
|
||||
*/
|
||||
void*
|
||||
|
Loading…
Reference in New Issue
Block a user