Use uint instead of int to improve code generation for bounds checking

This commit is contained in:
gingerBill
2022-09-27 22:31:46 +01:00
parent 35e70f4be1
commit c4d19dfa92
5 changed files with 9 additions and 12 deletions
+2 -2
View File
@@ -321,14 +321,14 @@ last_ptr :: proc(array: $T/[]$E) -> ^E {
}
get :: proc(array: $T/[]$E, index: int) -> (value: E, ok: bool) {
if 0 <= index && index < len(array) {
if uint(index) < len(array) {
value = array[index]
ok = true
}
return
}
get_ptr :: proc(array: $T/[]$E, index: int) -> (value: ^E, ok: bool) {
if 0 <= index && index < len(array) {
if uint(index) < len(array) {
value = &array[index]
ok = true
}