aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjakubtomsu <66876057+jakubtomsu@users.noreply.github.com>2026-02-10 18:48:22 +0100
committerjakubtomsu <66876057+jakubtomsu@users.noreply.github.com>2026-02-10 18:48:22 +0100
commit53cb56cc2196cc435567a0293a639f59ffc2bc1c (patch)
treee64e875857cfb2ae449f31ae3c0a389490e54f87
parent8bfee542040edd2ab98bbeec35e8b85e587c8d2d (diff)
remove core:mem dependency from core:bytes
-rw-r--r--core/bytes/bytes.odin18
1 files changed, 12 insertions, 6 deletions
diff --git a/core/bytes/bytes.odin b/core/bytes/bytes.odin
index 79de89d2f..911c62d5d 100644
--- a/core/bytes/bytes.odin
+++ b/core/bytes/bytes.odin
@@ -1,8 +1,8 @@
// Procedures for manipulation of `[]byte` slices.
package bytes
+import "base:runtime"
import "base:intrinsics"
-import "core:mem"
import "core:simd"
import "core:unicode"
import "core:unicode/utf8"
@@ -40,7 +40,7 @@ clone :: proc(s: []byte, allocator := context.allocator, loc := #caller_location
return c[:len(s)]
}
-clone_safe :: proc(s: []byte, allocator := context.allocator, loc := #caller_location) -> (data: []byte, err: mem.Allocator_Error) {
+clone_safe :: proc(s: []byte, allocator := context.allocator, loc := #caller_location) -> (data: []byte, err: runtime.Allocator_Error) {
c := make([]byte, len(s), allocator, loc) or_return
copy(c, s)
return c[:len(s)], nil
@@ -48,7 +48,7 @@ clone_safe :: proc(s: []byte, allocator := context.allocator, loc := #caller_loc
ptr_from_slice :: ptr_from_bytes
ptr_from_bytes :: proc(str: []byte) -> ^byte {
- d := transmute(mem.Raw_String)str
+ d := transmute(runtime.Raw_String)str
return d.data
}
@@ -70,7 +70,13 @@ truncate_to_rune :: proc(str: []byte, r: rune) -> []byte {
// Compares two strings, returning a value representing which one comes first lexiographically.
// -1 for `a`; 1 for `b`, or 0 if they are equal.
compare :: proc(lhs, rhs: []byte) -> int {
- return mem.compare(lhs, rhs)
+ res := runtime.memory_compare(raw_data(lhs), raw_data(rhs), min(len(lhs), len(rhs)))
+ if res == 0 && len(lhs) != len(rhs) {
+ return len(lhs) <= len(rhs) ? -1 : +1
+ } else if len(lhs) == 0 && len(rhs) == 0 {
+ return 0
+ }
+ return res
}
contains_rune :: proc(s: []byte, r: rune) -> int {
@@ -176,7 +182,7 @@ join :: proc(a: [][]byte, sep: []byte, allocator := context.allocator) -> []byte
return b
}
-join_safe :: proc(a: [][]byte, sep: []byte, allocator := context.allocator) -> (data: []byte, err: mem.Allocator_Error) {
+join_safe :: proc(a: [][]byte, sep: []byte, allocator := context.allocator) -> (data: []byte, err: runtime.Allocator_Error) {
if len(a) == 0 {
return nil, nil
}
@@ -212,7 +218,7 @@ concatenate :: proc(a: [][]byte, allocator := context.allocator) -> []byte {
return b
}
-concatenate_safe :: proc(a: [][]byte, allocator := context.allocator) -> (data: []byte, err: mem.Allocator_Error) {
+concatenate_safe :: proc(a: [][]byte, allocator := context.allocator) -> (data: []byte, err: runtime.Allocator_Error) {
if len(a) == 0 {
return nil, nil
}