Commit 0f5944459beb952fd49461dfb3c2867de7df314b

Carlos Martín Nieto 2022-04-29T10:50:02

mwindow: use multiplication instesad of conditionals This is a very verbose way of performing a comparison where we already have the identity value with both signs. Instead of chainging several conditions, we can rely on the maths working out.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
diff --git a/src/libgit2/mwindow.c b/src/libgit2/mwindow.c
index 5c5f9a8..ad64949 100644
--- a/src/libgit2/mwindow.c
+++ b/src/libgit2/mwindow.c
@@ -240,9 +240,7 @@ static bool git_mwindow_scan_recently_used(
 		 * store it in the output parameter. If lru_window is NULL,
 		 * it's the first loop, so store it as well.
 		 */
-		if (!lru_window ||
-				(comparison_sign == GIT_MWINDOW__LRU && lru_window->last_used > w->last_used) ||
-				(comparison_sign == GIT_MWINDOW__MRU && lru_window->last_used < w->last_used)) {
+		if (!lru_window || (comparison_sign * w->last_used) > lru_window->last_used) {
 			lru_window = w;
 			lru_last = w_last;
 			found = true;