tree entries are sorted, so find_entry_by_name() can exit early
diff --git a/lib/object.c b/lib/object.c
index 2100b96..abcc58c 100644
--- a/lib/object.c
+++ b/lib/object.c
@@ -707,8 +707,14 @@ find_entry_by_name(struct got_tree_object *tree, const char *name, size_t len)
{
struct got_tree_entry *te;
+ /* Note that tree entries are sorted in strncmp() order. */
SIMPLEQ_FOREACH(te, &tree->entries.head, entry) {
- if (strncmp(te->name, name, len) == 0 && te->name[len] == '\0')
+ int cmp = strncmp(te->name, name, len);
+ if (cmp < 0)
+ continue;
+ if (cmp > 0)
+ break;
+ if (te->name[len] == '\0')
return te;
}
return NULL;