Unverified Commit 3628b5f7 authored by Hero Bird's avatar Hero Bird Committed by GitHub

Improve code for assert_index_within_bounds (#409)

* [core] improve code around assert_index_within_bounds

* [core] further simplify assert_index_within_bounds
parent 0c253cb6
Pipeline #93685 failed with stages
in 6 minutes and 3 seconds
......@@ -43,28 +43,17 @@ where
}
}
cfg_if::cfg_if! {
if #[cfg(debug_assertions)] {
impl<T> StorageStash<T>
where
T: PackedLayout,
{
fn assert_index_within_bounds(&self, index: u32) {
if index >= self.len() {
panic!(
"index out of bounds: the len is {} but the index is {}",
self.len(),
index
)
}
}
}
} else {
impl<T> StorageStash<T>
where
T: PackedLayout,
{
fn assert_index_within_bounds(&self, index: u32) {}
impl<T> StorageStash<T>
where
T: PackedLayout,
{
fn assert_index_within_bounds(&self, index: u32) {
if cfg!(debug_assertions) {
assert!(index < self.len(),
"index out of bounds: the len is {} but the index is {}",
self.len(),
index
)
}
}
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment