Skip to content

Commit 9a86bfd

Browse files
authored
Merge pull request #156 from Shnatsel/should-filter-bounds-check
Eliminate bounds checks from simple_threshold_horizontal()
2 parents 481096d + ed52f90 commit 9a86bfd

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

src/loop_filter.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ fn simple_threshold_vertical(
8989

9090
#[inline]
9191
fn simple_threshold_horizontal(filter_limit: i32, pixels: &[u8]) -> bool {
92+
assert!(pixels.len() >= 6); // one bounds check up front eliminates all subsequent checks in this function
9293
i32::from(diff(pixels[3], pixels[4])) * 2 + i32::from(diff(pixels[2], pixels[5])) / 2
9394
<= filter_limit
9495
}
@@ -113,6 +114,7 @@ fn should_filter_vertical(
113114
}
114115

115116
fn should_filter_horizontal(interior_limit: u8, edge_limit: u8, pixels: &[u8]) -> bool {
117+
assert!(pixels.len() >= 8); // one bounds check up front eliminates all subsequent checks in this function
116118
simple_threshold_horizontal(i32::from(edge_limit), pixels)
117119
// this looks like an erroneous way to compute differences between 8 points, but isn't:
118120
// there are actually only 6 diff comparisons required as per the spec:

0 commit comments

Comments
 (0)