mirror of
https://github.com/Ed94/Odin.git
synced 2026-06-24 14:45:00 -07:00
Add the inner for loop back in the logic
This could be easier to predict in cases where one of `left` and `right` is significantly greater than the other, and as such the same branch is taken multiple times in a row
This commit is contained in:
+16
-6
@@ -75,15 +75,25 @@ ptr_rotate :: proc(left: int, mid: ^$T, right: int) {
|
||||
// TODO(bill): Optimization with a buffer for smaller ranges
|
||||
for left > 0 && right > 0 {
|
||||
if left >= right {
|
||||
ptr_swap_non_overlapping(ptr_sub(mid, right), mid, right * size_of(T))
|
||||
mid = ptr_sub(mid, right)
|
||||
for {
|
||||
ptr_swap_non_overlapping(ptr_sub(mid, right), mid, right * size_of(T))
|
||||
mid = ptr_sub(mid, right)
|
||||
|
||||
left -= right
|
||||
left -= right
|
||||
if left < right {
|
||||
break
|
||||
}
|
||||
}
|
||||
} else {
|
||||
ptr_swap_non_overlapping(ptr_sub(mid, left), mid, left * size_of(T))
|
||||
mid = ptr_add(mid, left)
|
||||
for {
|
||||
ptr_swap_non_overlapping(ptr_sub(mid, left), mid, left * size_of(T))
|
||||
mid = ptr_add(mid, left)
|
||||
|
||||
right -= left
|
||||
right -= left
|
||||
if right < left {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user