Browse Source

Replace `mem` with `runtime` in `core:slice`

gingerBill 2 years ago
parent
commit
d50a844720
2 changed files with 28 additions and 22 deletions
  1. 10 10
      core/slice/ptr.odin
  2. 18 12
      core/slice/slice.odin

+ 10 - 10
core/slice/ptr.odin

@@ -1,7 +1,7 @@
 package slice
 package slice
 
 
 import "core:builtin"
 import "core:builtin"
-import "core:mem"
+import "core:runtime"
 
 
 ptr_add :: proc(p: $P/^$T, x: int) -> ^T {
 ptr_add :: proc(p: $P/^$T, x: int) -> ^T {
 	return ([^]T)(p)[x:]
 	return ([^]T)(p)[x:]
@@ -27,9 +27,9 @@ ptr_swap_non_overlapping :: proc(x, y: rawptr, len: int) {
 		a := rawptr(uintptr(x) + uintptr(i))
 		a := rawptr(uintptr(x) + uintptr(i))
 		b := rawptr(uintptr(y) + uintptr(i))
 		b := rawptr(uintptr(y) + uintptr(i))
 
 
-		mem.copy(t, a, BLOCK_SIZE)
-		mem.copy(a, b, BLOCK_SIZE)
-		mem.copy(b, t, BLOCK_SIZE)
+		runtime.mem_copy(t, a, BLOCK_SIZE)
+		runtime.mem_copy(a, b, BLOCK_SIZE)
+		runtime.mem_copy(b, t, BLOCK_SIZE)
 	}
 	}
 
 
 	if i < len {
 	if i < len {
@@ -38,9 +38,9 @@ ptr_swap_non_overlapping :: proc(x, y: rawptr, len: int) {
 		a := rawptr(uintptr(x) + uintptr(i))
 		a := rawptr(uintptr(x) + uintptr(i))
 		b := rawptr(uintptr(y) + uintptr(i))
 		b := rawptr(uintptr(y) + uintptr(i))
 
 
-		mem.copy(t, a, rem)
-		mem.copy(a, b, rem)
-		mem.copy(b, t, rem)
+		runtime.mem_copy(t, a, rem)
+		runtime.mem_copy(a, b, rem)
+		runtime.mem_copy(b, t, rem)
 	}
 	}
 }
 }
 
 
@@ -59,9 +59,9 @@ ptr_swap_overlapping :: proc(x, y: rawptr, len: int) {
 	
 	
 	for n := len; n > 0; n -= N {
 	for n := len; n > 0; n -= N {
 		m := builtin.min(n, N)
 		m := builtin.min(n, N)
-		mem.copy(&buffer, a, m)
-		mem.copy(a, b, m)
-		mem.copy(b, &buffer, m)
+		runtime.mem_copy(&buffer, a, m)
+		runtime.mem_copy(a, b, m)
+		runtime.mem_copy(b, &buffer, m)
 		
 		
 		a, b = a[N:], b[N:]
 		a, b = a[N:], b[N:]
 	}
 	}

+ 18 - 12
core/slice/slice.odin

@@ -3,12 +3,12 @@ package slice
 import "core:intrinsics"
 import "core:intrinsics"
 import "core:builtin"
 import "core:builtin"
 import "core:math/bits"
 import "core:math/bits"
-import "core:mem"
+import "core:runtime"
 
 
 _ :: intrinsics
 _ :: intrinsics
 _ :: builtin
 _ :: builtin
 _ :: bits
 _ :: bits
-_ :: mem
+_ :: runtime
 
 
 /*
 /*
 	Turn a pointer and a length into a slice.
 	Turn a pointer and a length into a slice.
@@ -164,7 +164,7 @@ equal :: proc(a, b: $T/[]$E) -> bool where intrinsics.type_is_comparable(E) {
 		return false
 		return false
 	}
 	}
 	when intrinsics.type_is_simple_compare(E) {
 	when intrinsics.type_is_simple_compare(E) {
-		return mem.compare_ptrs(raw_data(a), raw_data(b), len(a)*size_of(E)) == 0
+		return runtime.memory_compare(raw_data(a), raw_data(b), len(a)*size_of(E)) == 0
 	} else {
 	} else {
 		for i in 0..<len(a) {
 		for i in 0..<len(a) {
 			if a[i] != b[i] {
 			if a[i] != b[i] {
@@ -180,7 +180,7 @@ simple_equal :: proc(a, b: $T/[]$E) -> bool where intrinsics.type_is_simple_comp
 	if len(a) != len(b) {
 	if len(a) != len(b) {
 		return false
 		return false
 	}
 	}
-	return mem.compare_ptrs(raw_data(a), raw_data(b), len(a)*size_of(E)) == 0
+	return runtime.memory_compare(raw_data(a), raw_data(b), len(a)*size_of(E)) == 0
 }
 }
 
 
 /*
 /*
@@ -220,6 +220,12 @@ has_suffix :: proc(array: $T/[]$E, needle: E) -> bool where intrinsics.type_is_c
 	return false
 	return false
 }
 }
 
 
+zero :: proc(array: $T/[]$E) #no_bounds_check {
+	if len(array) > 0 {
+		intrinsics.mem_zero(raw_data(array), size_of(E)*len(array))
+	}
+}
+
 fill :: proc(array: $T/[]$E, value: E) #no_bounds_check {
 fill :: proc(array: $T/[]$E, value: E) #no_bounds_check {
 	if len(array) <= 0 {
 	if len(array) <= 0 {
 		return
 		return
@@ -250,7 +256,7 @@ swap_with_slice :: proc(a, b: $T/[]$E, loc := #caller_location) {
 }
 }
 
 
 @(require_results)
 @(require_results)
-concatenate :: proc(a: []$T/[]$E, allocator := context.allocator) -> (res: T, err: mem.Allocator_Error) #optional_allocator_error {
+concatenate :: proc(a: []$T/[]$E, allocator := context.allocator) -> (res: T, err: runtime.Allocator_Error) #optional_allocator_error {
 	if len(a) == 0 {
 	if len(a) == 0 {
 		return
 		return
 	}
 	}
@@ -268,7 +274,7 @@ concatenate :: proc(a: []$T/[]$E, allocator := context.allocator) -> (res: T, er
 
 
 // copies a slice into a new slice
 // copies a slice into a new slice
 @(require_results)
 @(require_results)
-clone :: proc(a: $T/[]$E, allocator := context.allocator) -> ([]E, mem.Allocator_Error) #optional_allocator_error {
+clone :: proc(a: $T/[]$E, allocator := context.allocator) -> ([]E, runtime.Allocator_Error) #optional_allocator_error {
 	d, err := make([]E, len(a), allocator)
 	d, err := make([]E, len(a), allocator)
 	copy(d[:], a)
 	copy(d[:], a)
 	return d, err
 	return d, err
@@ -276,7 +282,7 @@ clone :: proc(a: $T/[]$E, allocator := context.allocator) -> ([]E, mem.Allocator
 
 
 
 
 // copies slice into a new dynamic array
 // copies slice into a new dynamic array
-clone_to_dynamic :: proc(a: $T/[]$E, allocator := context.allocator) -> ([dynamic]E, mem.Allocator_Error) #optional_allocator_error {
+clone_to_dynamic :: proc(a: $T/[]$E, allocator := context.allocator) -> ([dynamic]E, runtime.Allocator_Error) #optional_allocator_error {
 	d, err := make([dynamic]E, len(a), allocator)
 	d, err := make([dynamic]E, len(a), allocator)
 	copy(d[:], a)
 	copy(d[:], a)
 	return d, err
 	return d, err
@@ -286,12 +292,12 @@ to_dynamic :: clone_to_dynamic
 // Converts slice into a dynamic array without cloning or allocating memory
 // Converts slice into a dynamic array without cloning or allocating memory
 @(require_results)
 @(require_results)
 into_dynamic :: proc(a: $T/[]$E) -> [dynamic]E {
 into_dynamic :: proc(a: $T/[]$E) -> [dynamic]E {
-	s := transmute(mem.Raw_Slice)a
-	d := mem.Raw_Dynamic_Array{
+	s := transmute(runtime.Raw_Slice)a
+	d := runtime.Raw_Dynamic_Array{
 		data = s.data,
 		data = s.data,
 		len  = 0,
 		len  = 0,
 		cap  = s.len,
 		cap  = s.len,
-		allocator = mem.nil_allocator(),
+		allocator = runtime.nil_allocator(),
 	}
 	}
 	return transmute([dynamic]E)d
 	return transmute([dynamic]E)d
 }
 }
@@ -373,7 +379,7 @@ as_ptr :: proc(array: $T/[]$E) -> [^]E {
 
 
 
 
 @(require_results)
 @(require_results)
-mapper :: proc(s: $S/[]$U, f: proc(U) -> $V, allocator := context.allocator) -> (r: []V, err: mem.Allocator_Error) #optional_allocator_error {
+mapper :: proc(s: $S/[]$U, f: proc(U) -> $V, allocator := context.allocator) -> (r: []V, err: runtime.Allocator_Error) #optional_allocator_error {
 	r = make([]V, len(s), allocator) or_return
 	r = make([]V, len(s), allocator) or_return
 	for v, i in s {
 	for v, i in s {
 		r[i] = f(v)
 		r[i] = f(v)
@@ -402,7 +408,7 @@ filter :: proc(s: $S/[]$U, f: proc(U) -> bool, allocator := context.allocator) -
 }
 }
 
 
 @(require_results)
 @(require_results)
-scanner :: proc (s: $S/[]$U, initializer: $V, f: proc(V, U) -> V, allocator := context.allocator) -> (res: []V, err: mem.Allocator_Error) #optional_allocator_error {
+scanner :: proc (s: $S/[]$U, initializer: $V, f: proc(V, U) -> V, allocator := context.allocator) -> (res: []V, err: runtime.Allocator_Error) #optional_allocator_error {
 	if len(s) == 0 { return }
 	if len(s) == 0 { return }
 
 
 	res = make([]V, len(s), allocator) or_return
 	res = make([]V, len(s), allocator) or_return