mirror of
https://github.com/Rockbox/rockbox.git
synced 2025-12-08 12:45:26 -05:00
buflib: update first_free_handle in handle_alloc
Since we're scanning the handle table for the first free slot, we know none of the scanned slots are free. Use that knowledge to update first_free_handle and avoid rescanning filled slots again when the next handle is allocated. Change-Id: I457372f66c231168cfffa7e905d1e9fb80002f5f
This commit is contained in:
parent
f622bcfe4f
commit
840f6b79c7
1 changed files with 9 additions and 0 deletions
|
|
@ -196,8 +196,17 @@ union buflib_data* handle_alloc(struct buflib_context *ctx)
|
|||
if (handle >= ctx->alloc_end)
|
||||
ctx->last_handle--;
|
||||
else
|
||||
{
|
||||
/* We know the table is full, so update first_free_handle */
|
||||
ctx->first_free_handle = ctx->last_handle - 1;
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/* We know there are no free handles between the old first_free_handle
|
||||
* and the found handle, therefore we can update first_free_handle */
|
||||
ctx->first_free_handle = handle - 1;
|
||||
|
||||
handle->val = -1;
|
||||
return handle;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue