Browse Source

Correct slice/ptr.odin calls

gingerBill 2 years ago
parent
commit
756c1b7bcb
1 changed files with 9 additions and 7 deletions
  1. 9 7
      core/slice/ptr.odin

+ 9 - 7
core/slice/ptr.odin

@@ -4,10 +4,10 @@ import "core:builtin"
 import "core:mem"
 import "core:mem"
 
 
 ptr_add :: proc(p: $P/^$T, x: int) -> ^T {
 ptr_add :: proc(p: $P/^$T, x: int) -> ^T {
-	return (^T)(uintptr(p) + size_of(T)*x)
+	return ([^]T)(p)[x:]
 }
 }
 ptr_sub :: proc(p: $P/^$T, x: int) -> ^T {
 ptr_sub :: proc(p: $P/^$T, x: int) -> ^T {
-	return #force_inline ptr_add(p, -x)
+	return ([^]T)(p)[-x:]
 }
 }
 
 
 ptr_swap_non_overlapping :: proc(x, y: rawptr, len: int) {
 ptr_swap_non_overlapping :: proc(x, y: rawptr, len: int) {
@@ -84,12 +84,14 @@ ptr_rotate :: proc(left: int, mid: ^$T, right: int) {
 				}
 				}
 			}
 			}
 		} else {
 		} else {
-			ptr_swap_non_overlapping(ptr_sub(mid, left), mid, left)
-			mid = ptr_add(mid, left)
+			for {
+				ptr_swap_non_overlapping(ptr_sub(mid, left), mid, left)
+				mid = ptr_add(mid, left)
 
 
-			right -= left
-			if right < left {
-				break
+				right -= left
+				if right < left {
+					break
+				}
 			}
 			}
 		}
 		}
 	}
 	}