diff options
author | Carlos Martín Nieto <cmn@dwim.me> | 2014-06-09 04:38:22 +0200 |
---|---|---|
committer | Carlos Martín Nieto <cmn@dwim.me> | 2014-06-10 15:14:13 +0200 |
commit | 4d3f1f97404b01cd00ad5b2f47f64672d787e901 (patch) | |
tree | 3e1463a9d8fc93ad43dc10bc7034db466c4dfbc9 /tests | |
parent | 7064cdafbd25f66de016467b381d9f4474fba40a (diff) | |
download | libgit2-4d3f1f97404b01cd00ad5b2f47f64672d787e901.tar.gz |
treebuilder: use a map instead of vector to store the entries
Finding a filename in a vector means we need to resort it every time we
want to read from it, which includes every time we want to write to it
as well, as we want to find duplicate keys.
A hash-map fits what we want to do much more accurately, as we do not
care about sorting, but just the particular filename.
We still keep removed entries around, as the interface let you assume
they were going to be around until the treebuilder is cleared or freed,
but in this case that involves an append to a vector in the filter case,
which can now fail.
The only time we care about sorting is when we write out the tree, so
let's make that the only time we do any sorting.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/object/tree/write.c | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/tests/object/tree/write.c b/tests/object/tree/write.c index 45356e807..ddb62e278 100644 --- a/tests/object/tree/write.c +++ b/tests/object/tree/write.c @@ -104,6 +104,7 @@ void test_object_tree_write__subtree(void) void test_object_tree_write__sorted_subtrees(void) { git_treebuilder *builder; + git_tree *tree; unsigned int i; int position_c = -1, position_cake = -1, position_config = -1; @@ -143,8 +144,9 @@ void test_object_tree_write__sorted_subtrees(void) cl_git_pass(git_treebuilder_write(&tree_oid, g_repo, builder)); - for (i = 0; i < builder->entries.length; ++i) { - git_tree_entry *entry = git_vector_get(&builder->entries, i); + cl_git_pass(git_tree_lookup(&tree, g_repo, &tree_oid)); + for (i = 0; i < git_tree_entrycount(tree); i++) { + const git_tree_entry *entry = git_tree_entry_byindex(tree, i); if (strcmp(entry->filename, "c") == 0) position_c = i; @@ -156,6 +158,8 @@ void test_object_tree_write__sorted_subtrees(void) position_config = i; } + git_tree_free(tree); + cl_assert(position_c != -1); cl_assert(position_cake != -1); cl_assert(position_config != -1); |