mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-05 15:18:49 +00:00
bytes: fix last_index_byte off-by-one
This commit is contained in:
@@ -476,11 +476,9 @@ last_index_byte :: proc(s: []byte, c: byte) -> int #no_bounds_check {
|
|||||||
// worth vectorizing assuming there is a hardware vector unit, and
|
// worth vectorizing assuming there is a hardware vector unit, and
|
||||||
// the data size is large enough.
|
// the data size is large enough.
|
||||||
if i < SIMD_REG_SIZE_128 {
|
if i < SIMD_REG_SIZE_128 {
|
||||||
if i > 0 { // Handle s == nil.
|
#reverse for ch, j in s {
|
||||||
for /**/; i >= 0; i -= 1 {
|
if ch == c {
|
||||||
if s[i] == c {
|
return j
|
||||||
return i
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return -1
|
return -1
|
||||||
|
|||||||
@@ -87,3 +87,11 @@ test_index_byte_zero :: proc(t: ^testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@test
|
||||||
|
test_last_index_byte_bounds :: proc(t: ^testing.T) {
|
||||||
|
input := "helloworld.odin."
|
||||||
|
assert(len(input) == 16)
|
||||||
|
idx := bytes.last_index_byte(transmute([]byte)(input[:len(input)-1]), '.')
|
||||||
|
testing.expect_value(t, idx, 10)
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user