Rockbox open source high quality audio player as a Music Player Daemon
mpris rockbox mpd libadwaita audio rust zig deno
2
fork

Configure Feed

Select the types of activity you want to include in your feed.

buflib: optimize find_block_before

Exiting the loop implies next_block == block, so remove that check.
The check ret < block is false only if block is the first block, which
can be checked before the loop, saving a few cycles in that case.

Change-Id: Id493b5259a23a35a70b09dfe4bc4eacaf420760c

+10 -11
+10 -11
firmware/buflib.c
··· 664 664 union buflib_data *ret = ctx->buf_start, 665 665 *next_block = ret; 666 666 667 + /* no previous block */ 668 + if (next_block == block) 669 + return NULL; 670 + 667 671 /* find the block that's before the current one */ 668 - while (next_block < block) 672 + while (next_block != block) 669 673 { 670 674 ret = next_block; 671 675 next_block += abs(ret->val); 672 676 } 673 677 674 - /* If next_block == block, the above loop didn't go anywhere. If it did, 675 - * and the block before this one is empty, that is the wanted one 676 - */ 677 - if (next_block == block && ret < block) 678 - { 679 - if (is_free && ret->val >= 0) /* NULL if found block isn't free */ 680 - return NULL; 681 - return ret; 682 - } 683 - return NULL; 678 + /* don't return it if the found block isn't free */ 679 + if (is_free && ret->val >= 0) 680 + return NULL; 681 + 682 + return ret; 684 683 } 685 684 686 685 /* Free the buffer associated with handle_num. */