From 027ea587fcdcc7a7ac7c26e7ccd9ee31e587649d Mon Sep 17 00:00:00 2001 From: gingerBill Date: Fri, 26 Aug 2022 16:45:40 +0100 Subject: [PATCH] Unify mem and runtime logic --- core/mem/mem.odin | 43 +------------------------------------------ 1 file changed, 1 insertion(+), 42 deletions(-) diff --git a/core/mem/mem.odin b/core/mem/mem.odin index 7295a2afa..f7be69adc 100644 --- a/core/mem/mem.odin +++ b/core/mem/mem.odin @@ -54,48 +54,7 @@ compare :: proc "contextless" (a, b: []byte) -> int { } compare_byte_ptrs :: proc "contextless" (a, b: ^byte, n: int) -> int #no_bounds_check { - switch { - case a == b: - return 0 - case a == nil: - return -1 - case b == nil: - return -1 - case n == 0: - return 0 - } - - x := slice_ptr(a, n) - y := slice_ptr(b, n) - - SU :: size_of(uintptr) - fast := n/SU + 1 - offset := (fast-1)*SU - curr_block := 0 - if n < SU { - fast = 0 - } - - la := slice_ptr((^uintptr)(a), fast) - lb := slice_ptr((^uintptr)(b), fast) - - for /**/; curr_block < fast; curr_block += 1 { - if la[curr_block] ~ lb[curr_block] != 0 { - for pos := curr_block*SU; pos < n; pos += 1 { - if x[pos] ~ y[pos] != 0 { - return (int(x[pos]) - int(y[pos])) < 0 ? -1 : +1 - } - } - } - } - - for /**/; offset < n; offset += 1 { - if x[offset] ~ y[offset] != 0 { - return (int(x[offset]) - int(y[offset])) < 0 ? -1 : +1 - } - } - - return 0 + return runtime.memory_compare(a, b, n) } check_zero :: proc(data: []byte) -> bool {