From fc4364696556678f4cac4f6cefed17b94b4ec776 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn=20Nieto?= Date: Sun, 6 Dec 2015 22:51:00 +0100 Subject: [PATCH] tree: mark a tree as already sorted The trees are sorted on-disk, so we don't have to go over them again. This cuts almost a fifth of time spent parsing trees. --- CHANGELOG.md | 4 ++++ src/tree.c | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 196ad705a..a2dd76eba 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,10 @@ v0.23 + 1 * You can now set your own user-agent to be sent for HTTP requests by using the `GIT_OPT_SET_USER_AGENT` with `git_libgit2_opts()`. +* Tree objects are now assumed to be sorted. If a tree is not + correctly formed, it will give bad results. This is the git approach + and cuts a significant amount of time when reading the trees. + ### API additions * `git_config_lock()` has been added, which allow for diff --git a/src/tree.c b/src/tree.c index 2de8e72e1..aab4b58ad 100644 --- a/src/tree.c +++ b/src/tree.c @@ -476,7 +476,8 @@ int git_tree__parse(void *_tree, git_odb_object *odb_obj) buffer += GIT_OID_RAWSZ; } - git_vector_sort(&tree->entries); + /* The tree is sorted by definition. Bad inputs give bad outputs */ + tree->entries.flags |= GIT_VECTOR_SORTED; return 0; }