From b320e8d9a3728fbb02763b049908a24f6284bf21 Mon Sep 17 00:00:00 2001 From: blueloveTH Date: Wed, 12 Mar 2025 19:24:20 +0800 Subject: [PATCH] Update algorithm.h --- include/pocketpy/common/algorithm.h | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/include/pocketpy/common/algorithm.h b/include/pocketpy/common/algorithm.h index 8f4f5b88..7a334865 100644 --- a/include/pocketpy/common/algorithm.h +++ b/include/pocketpy/common/algorithm.h @@ -8,7 +8,7 @@ do { \ T* __first = ptr; \ int __len = count; \ - while(__len > 8) { \ + while(__len >= 8) { \ int __l2 = __len >> 1; \ T* __m = __first + __l2; \ if(less((*__m), (key))) { \ @@ -18,9 +18,23 @@ __len = __l2; \ } \ } \ - while(__len && less(*__first, (key))) { \ - ++__first; \ - --__len; \ + switch(__len) { \ + case 7: \ + if(less(*__first, (key))) __first++; \ + case 6: \ + if(less(*__first, (key))) __first++; \ + case 5: \ + if(less(*__first, (key))) __first++; \ + case 4: \ + if(less(*__first, (key))) __first++; \ + case 3: \ + if(less(*__first, (key))) __first++; \ + case 2: \ + if(less(*__first, (key))) __first++; \ + case 1: \ + if(less(*__first, (key))) __first++; \ + case 0: break; \ + default: c11__unreachable(); \ } \ *(out_index) = __first - (T*)(ptr); \ } while(0)