diff --git a/core/bytes/bytes.odin b/core/bytes/bytes.odin index 5a510951e..45eb44307 100644 --- a/core/bytes/bytes.odin +++ b/core/bytes/bytes.odin @@ -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 // the data size is large enough. if i < SIMD_REG_SIZE_128 { - if i > 0 { // Handle s == nil. - for /**/; i >= 0; i -= 1 { - if s[i] == c { - return i - } + #reverse for ch, j in s { + if ch == c { + return j } } return -1 diff --git a/tests/core/bytes/test_core_bytes.odin b/tests/core/bytes/test_core_bytes.odin index fb3c460aa..7f078c423 100644 --- a/tests/core/bytes/test_core_bytes.odin +++ b/tests/core/bytes/test_core_bytes.odin @@ -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) +} \ No newline at end of file