mirror of
https://github.com/Ed94/Odin.git
synced 2026-07-28 18:30:06 +00:00
Merge core:simd/util into core:bytes
This commit is contained in:
@@ -2,8 +2,8 @@
|
||||
package strings
|
||||
|
||||
import "base:intrinsics"
|
||||
import "core:bytes"
|
||||
import "core:io"
|
||||
@require import simd_util "core:simd/util"
|
||||
import "core:mem"
|
||||
import "core:unicode"
|
||||
import "core:unicode/utf8"
|
||||
@@ -1426,23 +1426,7 @@ Output:
|
||||
|
||||
*/
|
||||
index_byte :: proc(s: string, c: byte) -> (res: int) {
|
||||
_index_byte :: #force_inline proc "contextless" (s: string, c: byte) -> int {
|
||||
for i := 0; i < len(s); i += 1 {
|
||||
if s[i] == c {
|
||||
return i
|
||||
}
|
||||
}
|
||||
return -1
|
||||
}
|
||||
|
||||
// NOTE(Feoramund): On my Alder Lake CPU, I have only witnessed a
|
||||
// significant speedup when compiling in either Size or Speed mode.
|
||||
// The SIMD version is usually 2-3x slower without optimizations on.
|
||||
when ODIN_OPTIMIZATION_MODE > .Minimal {
|
||||
return #force_inline simd_util.index_byte(transmute([]u8)s, c)
|
||||
} else {
|
||||
return _index_byte(s, c)
|
||||
}
|
||||
return #force_inline bytes.index_byte(transmute([]u8)s, c)
|
||||
}
|
||||
/*
|
||||
Returns the byte offset of the last byte `c` in the string `s`, -1 when not found.
|
||||
@@ -1477,20 +1461,7 @@ Output:
|
||||
|
||||
*/
|
||||
last_index_byte :: proc(s: string, c: byte) -> (res: int) {
|
||||
_last_index_byte :: #force_inline proc "contextless" (s: string, c: byte) -> int {
|
||||
for i := len(s)-1; i >= 0; i -= 1 {
|
||||
if s[i] == c {
|
||||
return i
|
||||
}
|
||||
}
|
||||
return -1
|
||||
}
|
||||
|
||||
when ODIN_OPTIMIZATION_MODE > .Minimal {
|
||||
return #force_inline simd_util.last_index_byte(transmute([]u8)s, c)
|
||||
} else {
|
||||
return _last_index_byte(s, c)
|
||||
}
|
||||
return #force_inline bytes.last_index_byte(transmute([]u8)s, c)
|
||||
}
|
||||
/*
|
||||
Returns the byte offset of the first rune `r` in the string `s` it finds, -1 when not found.
|
||||
|
||||
Reference in New Issue
Block a user