Commit 4b9176646e568036623abaee94c8cff7b5e37e09

Stefan Sperling 2018-11-17T16:34:00

make diff's match_entry_by_name() exit early if possible

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
diff --git a/lib/diff.c b/lib/diff.c
index be49c12..af94e1b 100644
--- a/lib/diff.c
+++ b/lib/diff.c
@@ -162,7 +162,13 @@ match_entry_by_name(struct got_tree_entry *te1, struct got_tree_object *tree2)
 
 	entries2 = got_object_tree_get_entries(tree2); 
 	SIMPLEQ_FOREACH(te2, &entries2->head, entry) {
-		if (strcmp(te1->name, te2->name) == 0)
+		/* Note that tree entries are sorted in strcmp() order. */
+		int cmp = strcmp(te1->name, te2->name);
+		if (cmp < 0)
+			continue;
+		else if (cmp > 0)
+			break;
+		else
 			return te2;
 	}
 	return NULL;