Skip to content

Commit 2947923

Browse files
committed
Merge branch 'rs/list-optim'
Fix a couple of "accumulate into a sorted list" to "accumulate and then sort the list". * rs/list-optim: walker: avoid quadratic list insertion in mark_complete sha1_name: avoid quadratic list insertion in handle_one_ref
2 parents b6a1261 + 3bc7a05 commit 2947923

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

sha1_name.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -839,7 +839,7 @@ static int handle_one_ref(const char *path,
839839
}
840840
if (object->type != OBJ_COMMIT)
841841
return 0;
842-
commit_list_insert_by_date((struct commit *)object, list);
842+
commit_list_insert((struct commit *)object, list);
843843
return 0;
844844
}
845845

@@ -1366,6 +1366,7 @@ static int get_sha1_with_context_1(const char *name,
13661366
if (!only_to_die && namelen > 2 && name[1] == '/') {
13671367
struct commit_list *list = NULL;
13681368
for_each_ref(handle_one_ref, &list);
1369+
commit_list_sort_by_date(&list);
13691370
return get_sha1_oneline(name + 2, sha1, list);
13701371
}
13711372
if (namelen < 3 ||

walker.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ static int mark_complete(const char *path, const unsigned char *sha1, int flag,
205205
struct commit *commit = lookup_commit_reference_gently(sha1, 1);
206206
if (commit) {
207207
commit->object.flags |= COMPLETE;
208-
commit_list_insert_by_date(commit, &complete);
208+
commit_list_insert(commit, &complete);
209209
}
210210
return 0;
211211
}
@@ -267,8 +267,11 @@ int walker_fetch(struct walker *walker, int targets, char **target,
267267
goto done;
268268
}
269269
}
270-
if (!walker->get_recover)
270+
271+
if (!walker->get_recover) {
271272
for_each_ref(mark_complete, NULL);
273+
commit_list_sort_by_date(&complete);
274+
}
272275

273276
for (i = 0; i < targets; i++) {
274277
if (interpret_target(walker, target[i], &sha1[20 * i])) {

0 commit comments

Comments
 (0)