From: Junio C Hamano Date: Wed, 29 May 2013 21:29:58 +0000 (-0700) Subject: Merge branch 'jk/lookup-object-prefer-latest' X-Git-Tag: v1.8.4-rc0~247 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/4818cfcdcc8011e5eef353d0f64cd9d2374ea381?ds=inline;hp=-c Merge branch 'jk/lookup-object-prefer-latest' Optimizes object lookup when the object hashtable starts to become crowded. * jk/lookup-object-prefer-latest: lookup_object: prioritize recently found objects --- 4818cfcdcc8011e5eef353d0f64cd9d2374ea381 diff --combined object.c index 20703f52ed,3fb1caa29f..88d0bece81 --- a/object.c +++ b/object.c @@@ -71,13 -71,13 +71,13 @@@ static unsigned int hashtable_index(con struct object *lookup_object(const unsigned char *sha1) { - unsigned int i; + unsigned int i, first; struct object *obj; if (!obj_hash) return NULL; - i = hashtable_index(sha1); + first = i = hashtable_index(sha1); while ((obj = obj_hash[i]) != NULL) { if (!hashcmp(sha1, obj->sha1)) break; @@@ -85,6 -85,16 +85,16 @@@ if (i == obj_hash_size) i = 0; } + if (obj && i != first) { + /* + * Move object to where we started to look for it so + * that we do not need to walk the hash table the next + * time we look for it. + */ + struct object *tmp = obj_hash[i]; + obj_hash[i] = obj_hash[first]; + obj_hash[first] = tmp; + } return obj; } @@@ -185,16 -195,6 +195,16 @@@ struct object *parse_object_buffer(cons return obj; } +struct object *parse_object_or_die(const unsigned char *sha1, + const char *name) +{ + struct object *o = parse_object(sha1); + if (o) + return o; + + die(_("unable to parse object: %s"), name ? name : sha1_to_hex(sha1)); +} + struct object *parse_object(const unsigned char *sha1) { unsigned long size;