On 11/26/26 17:53, Peder Bergan via B4 Relay wrote:
From: Peder Bergan <[email protected]>

is_alignment() scans pairs of alignment centers each time it tests
whether a module is reserved. At version 40 there are seven centers
per axis, so a lookup can visit 49 pairs.

Each center covers a five-module span, and adjacent centers are at
least 12 modules apart. Find the unique matching center on each axis
and apply the existing finder-pattern exclusion to that pair. The
lookup now needs at most 14 center tests.

Thanks for your contribution.
This code is executed only once when a panic occurs, so optimizations are clearly not a priority.
But this series looks good, and keeps the code simple.

Reviewed-by: Jocelyn Falempe <[email protected]>


Signed-off-by: Peder Bergan <[email protected]>
---
  drivers/gpu/drm/drm_panic_helper_qr.rs | 19 ++++++++-----------
  1 file changed, 8 insertions(+), 11 deletions(-)

diff --git a/drivers/gpu/drm/drm_panic_helper_qr.rs 
b/drivers/gpu/drm/drm_panic_helper_qr.rs
index 4941731fb60fa..c6ed395c05bd2 100644
--- a/drivers/gpu/drm/drm_panic_helper_qr.rs
+++ b/drivers/gpu/drm/drm_panic_helper_qr.rs
@@ -746,17 +746,14 @@ fn draw_alignments(&mut self) {
fn is_alignment(&self, x: u8, y: u8) -> bool {
          let positions = self.version.alignment_pattern();
-        for &ax in positions.iter() {
-            for &ay in positions.iter() {
-                if self.is_finder(ax, ay) {
-                    continue;
-                }
-                if x >= ax - 2 && x <= ax + 2 && y >= ay - 2 && y <= ay + 2 {
-                    return true;
-                }
-            }
-        }
-        false
+        // Centers are at least 12 modules apart, so their five-module spans 
are disjoint.
+        let Some(&ax) = positions.iter().find(|&&center| x.abs_diff(center) <= 
2) else {
+            return false;
+        };
+        let Some(&ay) = positions.iter().find(|&&center| y.abs_diff(center) <= 
2) else {
+            return false;
+        };
+        !self.is_finder(ax, ay)
      }
// Timing pattern: 2 dotted line between the finder patterns.


Reply via email to