diff options
author | Aidan MacDonald <amachronic@protonmail.com> | 2022-03-28 21:30:58 +0100 |
---|---|---|
committer | Aidan MacDonald <amachronic@protonmail.com> | 2022-09-19 15:09:51 -0400 |
commit | 840f6b79c73b7714843f38d179dbbd6bf45b822d (patch) | |
tree | fb0119c5e74c9199f0fd2f1280bc32380a8c269b /firmware | |
parent | f622bcfe4fd966af4c5ac5deadb4f3e74026078b (diff) | |
download | rockbox-840f6b79c73b7714843f38d179dbbd6bf45b822d.tar.gz rockbox-840f6b79c73b7714843f38d179dbbd6bf45b822d.zip |
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
Diffstat (limited to 'firmware')
-rw-r--r-- | firmware/buflib.c | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/firmware/buflib.c b/firmware/buflib.c index 05e489ea14..4b557eb59d 100644 --- a/firmware/buflib.c +++ b/firmware/buflib.c | |||
@@ -196,8 +196,17 @@ union buflib_data* handle_alloc(struct buflib_context *ctx) | |||
196 | if (handle >= ctx->alloc_end) | 196 | if (handle >= ctx->alloc_end) |
197 | ctx->last_handle--; | 197 | ctx->last_handle--; |
198 | else | 198 | else |
199 | { | ||
200 | /* We know the table is full, so update first_free_handle */ | ||
201 | ctx->first_free_handle = ctx->last_handle - 1; | ||
199 | return NULL; | 202 | return NULL; |
203 | } | ||
200 | } | 204 | } |
205 | |||
206 | /* We know there are no free handles between the old first_free_handle | ||
207 | * and the found handle, therefore we can update first_free_handle */ | ||
208 | ctx->first_free_handle = handle - 1; | ||
209 | |||
201 | handle->val = -1; | 210 | handle->val = -1; |
202 | return handle; | 211 | return handle; |
203 | } | 212 | } |