mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
Use usz and fix out of bounds access in branchless loop
This commit is contained in:
committed by
Christoffer Lerno
parent
db75da65db
commit
17ee3887dd
@@ -26,8 +26,8 @@ macro quicksort_indexed(list, start, end, cmp = EMPTY_MACRO_SLOT, context = EMPT
|
||||
|
||||
module std::sort::cs(<Type, KeyFn>);
|
||||
|
||||
def Counts = ulong[256] @private;
|
||||
def Ranges = ulong[257] @private;
|
||||
def Counts = usz[256] @private;
|
||||
def Ranges = usz[257] @private;
|
||||
def Indexs = char[256] @private;
|
||||
def ElementType = $typeof(Type{}[0]);
|
||||
|
||||
@@ -108,10 +108,13 @@ fn void csort(Type list, usz low, usz high, KeyFn key_fn, uint byte_idx)
|
||||
}
|
||||
ranges[256] = total;
|
||||
|
||||
for(ushort i = 0; i < 256; i++) {
|
||||
ushort remaining_indexs = 256 - (fallback0_count + recursion_count);
|
||||
for(ushort i = 0; (i < 256) && remaining_indexs; i++) {
|
||||
indexs[fallback0_count + fallback1_count] = (char)i;
|
||||
ushort count = ranges[i + 1] - ranges[i];
|
||||
fallback1_count += (ushort)(count > 32 && count <= 128);
|
||||
usz count = ranges[i + 1] - ranges[i];
|
||||
ushort within_fallback1_range = (ushort)(count > 32 && count <= 128);
|
||||
fallback1_count += within_fallback1_range;
|
||||
remaining_indexs -= within_fallback1_range;
|
||||
}
|
||||
|
||||
if (!keys_ordered)
|
||||
|
||||
Reference in New Issue
Block a user