This commit is contained in:
Folkert 2021-04-04 00:21:53 +02:00
parent 73cb826a98
commit c168f2751d
2 changed files with 13 additions and 23 deletions

View file

@ -690,6 +690,12 @@ fn listRangeHelp(allocator: *Allocator, comptime T: type, low: T, high: T) RocLi
} }
} }
inline fn swapHelp(width: usize, temporary: [*]u8, ptr1: [*]u8, ptr2: [*]u8) void {
@memcpy(temporary, ptr1, width);
@memcpy(ptr1, ptr2, width);
@memcpy(ptr2, temporary, width);
}
fn swap(source_ptr: [*]u8, element_width_initial: usize, index_1: usize, index_2: usize) void { fn swap(source_ptr: [*]u8, element_width_initial: usize, index_1: usize, index_2: usize) void {
const threshold: comptime usize = 64; const threshold: comptime usize = 64;
@ -703,26 +709,10 @@ fn swap(source_ptr: [*]u8, element_width_initial: usize, index_1: usize, index_2
while (true) { while (true) {
if (element_width < threshold) { if (element_width < threshold) {
swapHelp(element_width, buffer, element_at_i, element_at_j);
// Store I Element in temp
@memcpy(buffer, element_at_i, element_width);
// Swap I Element with J Element
@memcpy(element_at_i, element_at_j, element_width);
// Swap J Element with buffer
@memcpy(element_at_j, buffer, element_width);
return; return;
} else { } else {
// Store I Element in temp swapHelp(threshold, buffer, element_at_i, element_at_j);
@memcpy(buffer, element_at_i, threshold);
// Swap I Element with J Element
@memcpy(element_at_i, element_at_j, threshold);
// Swap J Element with buffer
@memcpy(element_at_j, buffer, threshold);
element_at_i += threshold; element_at_i += threshold;
element_at_j += threshold; element_at_j += threshold;
@ -744,12 +734,12 @@ fn partition(source_ptr: [*]u8, transform: Opaque, wrapper: CompareFn, element_w
const order = @intToEnum(utils.Ordering, ordering); const order = @intToEnum(utils.Ordering, ordering);
switch (order) { switch (order) {
utils.Ordering.LT, utils.Ordering.EQ => { utils.Ordering.LT => {
// the current element is smaller than the pivot; swap it // the current element is smaller than the pivot; swap it
i += 1; i += 1;
swap(source_ptr, element_width, @intCast(usize, i), @intCast(usize, j)); swap(source_ptr, element_width, @intCast(usize, i), @intCast(usize, j));
}, },
utils.Ordering.GT => {}, utils.Ordering.EQ, utils.Ordering.GT => {},
} }
} }
swap(source_ptr, element_width, @intCast(usize, i + 1), @intCast(usize, high)); swap(source_ptr, element_width, @intCast(usize, i + 1), @intCast(usize, high));
@ -761,8 +751,8 @@ fn quicksort(source_ptr: [*]u8, transform: Opaque, wrapper: CompareFn, element_w
// partition index // partition index
const pi = partition(source_ptr, transform, wrapper, element_width, low, high); const pi = partition(source_ptr, transform, wrapper, element_width, low, high);
const _unused1 = quicksort(source_ptr, transform, wrapper, element_width, low, pi - 1); // before pi _ = quicksort(source_ptr, transform, wrapper, element_width, low, pi - 1); // before pi
const _unused2 = quicksort(source_ptr, transform, wrapper, element_width, pi + 1, high); // after pi _ = quicksort(source_ptr, transform, wrapper, element_width, pi + 1, high); // after pi
} }
} }

View file

@ -463,7 +463,7 @@ pub fn build_compare_wrapper<'a, 'ctx, 'env>(
&[value1, value2], &[value1, value2],
"call_user_defined_function", "call_user_defined_function",
); );
// call.set_call_convention(user_defined_function.get_call_conventions());
let result = call.try_as_basic_value().left().unwrap(); let result = call.try_as_basic_value().left().unwrap();
// IMPORTANT! we call a user function, so it has the fast calling convention // IMPORTANT! we call a user function, so it has the fast calling convention