Skip to content

Commit 6eb2646

Browse files
committed
drivers: video: common: optimization in for exact matches
In video_closest_frmival(), immediately stop searching when an exact match is found, as a small performance optimization. Signed-off-by: Josuah Demangeon <me@josuah.net>
1 parent 426cefd commit 6eb2646

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

drivers/video/video_common.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,10 +153,16 @@ void video_closest_frmival(const struct device *dev, enum video_endpoint_id ep,
153153
a = video_frmival_nsec(&desired);
154154
b = video_frmival_nsec(&tmp);
155155
diff_nsec = a > b ? a - b : b - a;
156+
156157
if (diff_nsec < best_diff_nsec) {
157158
best_diff_nsec = diff_nsec;
158159
match->index = fie.index;
159160
memcpy(&match->discrete, &tmp, sizeof(tmp));
160161
}
162+
163+
if (diff_nsec == 0) {
164+
/* Exact match, stop searching a better match */
165+
break;
166+
}
161167
}
162168
}

0 commit comments

Comments
 (0)