mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-06 07:38:48 +00:00
Use usize for bounds checking in Array and Slice (compiler)
This commit is contained in:
+4
-4
@@ -10,14 +10,14 @@ struct Array {
|
|||||||
|
|
||||||
T &operator[](isize index) {
|
T &operator[](isize index) {
|
||||||
#if !defined(NO_ARRAY_BOUNDS_CHECK)
|
#if !defined(NO_ARRAY_BOUNDS_CHECK)
|
||||||
GB_ASSERT_MSG(0 <= index && index < count, "Index %td is out of bounds ranges 0..<%td", index, count);
|
GB_ASSERT_MSG(cast(usize)index < cast(usize)count, "Index %td is out of bounds ranges 0..<%td", index, count);
|
||||||
#endif
|
#endif
|
||||||
return data[index];
|
return data[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
T const &operator[](isize index) const {
|
T const &operator[](isize index) const {
|
||||||
#if !defined(NO_ARRAY_BOUNDS_CHECK)
|
#if !defined(NO_ARRAY_BOUNDS_CHECK)
|
||||||
GB_ASSERT_MSG(0 <= index && index < count, "Index %td is out of bounds ranges 0..<%td", index, count);
|
GB_ASSERT_MSG(cast(usize)index < cast(usize)count, "Index %td is out of bounds ranges 0..<%td", index, count);
|
||||||
#endif
|
#endif
|
||||||
return data[index];
|
return data[index];
|
||||||
}
|
}
|
||||||
@@ -58,14 +58,14 @@ struct Slice {
|
|||||||
|
|
||||||
gb_inline T &operator[](isize index) {
|
gb_inline T &operator[](isize index) {
|
||||||
#if !defined(NO_ARRAY_BOUNDS_CHECK)
|
#if !defined(NO_ARRAY_BOUNDS_CHECK)
|
||||||
GB_ASSERT_MSG(0 <= index && index < count, "Index %td is out of bounds ranges 0..<%td", index, count);
|
GB_ASSERT_MSG(cast(usize)index < cast(usize)count, "Index %td is out of bounds ranges 0..<%td", index, count);
|
||||||
#endif
|
#endif
|
||||||
return data[index];
|
return data[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
gb_inline T const &operator[](isize index) const {
|
gb_inline T const &operator[](isize index) const {
|
||||||
#if !defined(NO_ARRAY_BOUNDS_CHECK)
|
#if !defined(NO_ARRAY_BOUNDS_CHECK)
|
||||||
GB_ASSERT_MSG(0 <= index && index < count, "Index %td is out of bounds ranges 0..<%td", index, count);
|
GB_ASSERT_MSG(cast(usize)index < cast(usize)count, "Index %td is out of bounds ranges 0..<%td", index, count);
|
||||||
#endif
|
#endif
|
||||||
return data[index];
|
return data[index];
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user