This commit is contained in:
Gregory 2019-04-27 20:01:00 +03:00
parent 863d913ce3
commit d1633c62bb

View file

@ -2,28 +2,28 @@
void free(void *used) void free(void *used)
{ {
t_header *runner; t_header *pivot;
t_header *to_be_freed; t_header *to_be_freed;
to_be_freed = (t_header *)used - UINIT; to_be_freed = (t_header *)used - UINIT;
runner = free_blocks; pivot = free_blocks;
while(!(to_be_freed > runner && to_be_freed < runner->next)) while(!(to_be_freed > pivot && to_be_freed < pivot->next))
{ {
if (runner >= runner->next && (to_be_freed > runner || to_be_freed < runner->next)) if (pivot >= pivot->next && (to_be_freed > pivot || to_be_freed < pivot->next))
break ; break ;
runner = runner->next; pivot = pivot->next;
} }
if (to_be_freed + to_be_freed->units == runner->next) if (to_be_freed + to_be_freed->units == pivot->next)
{ {
to_be_freed->units += runner->units; to_be_freed->units += pivot->units;
to_be_freed->next = runner->next->next; to_be_freed->next = pivot->next->next;
} }
else if (runner + runner->units == to_be_freed) else if (pivot + pivot->units == to_be_freed)
{ {
runner->units += to_be_freed->units; pivot->units += to_be_freed->units;
runner->next = to_be_freed->next; pivot->next = to_be_freed->next;
} }
else else
runner->next = to_be_freed; pivot->next = to_be_freed;
free_blocks = runner; free_blocks = pivot;
} }