eliminate redundant cache search in got_object_open_as_tree()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
diff --git a/lib/object.c b/lib/object.c
index ef9404c..b794b8e 100644
--- a/lib/object.c
+++ b/lib/object.c
@@ -370,17 +370,20 @@ got_object_qid_alloc(struct got_object_qid **qid, struct got_object_id *id)
return NULL;
}
-const struct got_error *
-got_object_tree_open(struct got_tree_object **tree,
- struct got_repository *repo, struct got_object *obj)
+static const struct got_error *
+open_tree(struct got_tree_object **tree,
+ struct got_repository *repo, struct got_object *obj, int check_cache)
{
const struct got_error *err = NULL;
- *tree = got_repo_get_cached_tree(repo, &obj->id);
- if (*tree != NULL) {
- (*tree)->refcnt++;
- return NULL;
- }
+ if (check_cache) {
+ *tree = got_repo_get_cached_tree(repo, &obj->id);
+ if (*tree != NULL) {
+ (*tree)->refcnt++;
+ return NULL;
+ }
+ } else
+ *tree = NULL;
if (obj->type != GOT_OBJ_TYPE_TREE)
return got_error(GOT_ERR_OBJ_TYPE);
@@ -433,12 +436,19 @@ got_object_open_as_tree(struct got_tree_object **tree,
goto done;
}
- err = got_object_tree_open(tree, repo, obj);
+ err = open_tree(tree, repo, obj, 0);
done:
got_object_close(obj);
return err;
}
+const struct got_error *
+got_object_tree_open(struct got_tree_object **tree,
+ struct got_repository *repo, struct got_object *obj)
+{
+ return open_tree(tree, repo, obj, 1);
+}
+
const struct got_tree_entries *
got_object_tree_get_entries(struct got_tree_object *tree)
{