summaryrefslogtreecommitdiff
path: root/fast-import.c
diff options
context:
space:
mode:
authorDavid Barr <david.barr@cordelta.com>2010-11-23 01:53:48 -0600
committerJunio C Hamano <gitster@pobox.com>2010-11-24 11:25:16 -0800
commitb7c1ce4f14f37600a8a5bf8d81e0a723d42644b9 (patch)
tree51d785acce4edf3fd79dcd11eb50d4b282551c4f /fast-import.c
parent593ce2bea5dad436e87b5dd37c205961d73feae9 (diff)
downloadgit-b7c1ce4f14f37600a8a5bf8d81e0a723d42644b9.tar.gz
fast-import: insert new object entries at start of hash bucket
More often than not, find_object is called for recently inserted objects. Optimise for this case by inserting new entries at the start of the chain. This doesn't affect the cost of new inserts but reduces the cost of find and insert for existing object entries. Signed-off-by: David Barr <david.barr@cordelta.com> Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'fast-import.c')
-rw-r--r--fast-import.c9
1 files changed, 2 insertions, 7 deletions
diff --git a/fast-import.c b/fast-import.c
index 74f08bd554..89d074bbe4 100644
--- a/fast-import.c
+++ b/fast-import.c
@@ -539,22 +539,17 @@ static struct object_entry *insert_object(unsigned char *sha1)
{
unsigned int h = sha1[0] << 8 | sha1[1];
struct object_entry *e = object_table[h];
- struct object_entry *p = NULL;
while (e) {
if (!hashcmp(sha1, e->idx.sha1))
return e;
- p = e;
e = e->next;
}
e = new_object(sha1);
- e->next = NULL;
+ e->next = object_table[h];
e->idx.offset = 0;
- if (p)
- p->next = e;
- else
- object_table[h] = e;
+ object_table[h] = e;
return e;
}