git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 01/11] object.c: code movement for readability

From
Junio C Hamano <gitster@pobox.com>
Date
Aug 11, 2011, 17:53 UTC
Message-ID
<1313085196-13249-2-git-send-email-gitster@pobox.com>
In-Reply-To
<1313085196-13249-1-git-send-email-gitster@pobox.com>

This only moves the lines around a bit to gather the definitions of code and data that manage the hash function and the object hash table into one place (examine "blame -M" output to see nothing new is introduced).

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 object.c |   40 ++++++++++++++++++++--------------------
 1 files changed, 20 insertions(+), 20 deletions(-)
diff --git a/object.c b/object.c
index 31976b5..35ff130 100644
--- a/object.c
+++ b/object.c
@@ -5,19 +5,6 @@
 #include "commit.h"
 #include "tag.h"
 
-static struct object **obj_hash;
-static int nr_objs, obj_hash_size;
-
-unsigned int get_max_object_index(void)
-{
-	return obj_hash_size;
-}
-
-struct object *get_indexed_object(unsigned int idx)
-{
-	return obj_hash[idx];
-}
-
 static const char *object_type_strings[] = {
 	NULL,		/* OBJ_NONE = 0 */
 	"commit",	/* OBJ_COMMIT = 1 */
@@ -43,6 +30,19 @@ int type_from_string(const char *str)
 	die("invalid object type \"%s\"", str);
 }
 
+static struct object **obj_hash;
+static int nr_objs, obj_hash_size;
+
+unsigned int get_max_object_index(void)
+{
+	return obj_hash_size;
+}
+
+struct object *get_indexed_object(unsigned int idx)
+{
+	return obj_hash[idx];
+}
+
 static unsigned int hash_obj(struct object *obj, unsigned int n)
 {
 	unsigned int hash;
@@ -50,6 +50,13 @@ static unsigned int hash_obj(struct object *obj, unsigned int n)
 	return hash % n;
 }
 
+static unsigned int hashtable_index(const unsigned char *sha1)
+{
+	unsigned int i;
+	memcpy(&i, sha1, sizeof(unsigned int));
+	return i % obj_hash_size;
+}
+
 static void insert_obj_hash(struct object *obj, struct object **hash, unsigned int size)
 {
 	unsigned int j = hash_obj(obj, size);
@@ -62,13 +69,6 @@ static void insert_obj_hash(struct object *obj, struct object **hash, unsigned i
 	hash[j] = obj;
 }
 
-static unsigned int hashtable_index(const unsigned char *sha1)
-{
-	unsigned int i;
-	memcpy(&i, sha1, sizeof(unsigned int));
-	return i % obj_hash_size;
-}
-
 struct object *lookup_object(const unsigned char *sha1)
 {
 	unsigned int i;
-- 
1.7.6.433.g1421f
Previous: Junio C HamanoNext: Junio C Hamano
Message 2 of 15 in “Micro-optimizing lookup_object()”
  1. 00/11 Micro-optimizing lookup_object()Junio C Hamano, Aug 11, 2011
  2. 01/11 object.c: code movement for readabilityJunio C Hamano, Aug 11, 2011
  3. 02/11 object.c: remove duplicated code for object hashingJunio C Hamano, Aug 11, 2011
  4. 03/11 pack-objects --count-onlyJunio C Hamano, Aug 11, 2011
  5. 04/11 object: next_size() helper for readabilityJunio C Hamano, Aug 11, 2011
  6. 05/11 object hash: we know the table size is a power of twoJunio C Hamano, Aug 11, 2011
  7. 06/11 object: growing the hash-table more aggressively does not help muchJunio C Hamano, Aug 11, 2011
  8. 07/11 object: try naive cuckoo hashingJunio C Hamano, Aug 11, 2011
  9. 08/11 object: try 5-way cuckoo -- use all 20-bytes of SHA-1Junio C Hamano, Aug 11, 2011
  10. 09/11 object: try 4-way cuckooJunio C Hamano, Aug 11, 2011
  11. 10/11 object: try 3-way cuckooJunio C Hamano, Aug 11, 2011
  12. 11/11 object: try 2-way cuckoo againJunio C Hamano, Aug 11, 2011
  13. 12/11 object.c: make object hash implementation more opaqueJunio C Hamano, Aug 11, 2011
  14. git_checkattr() is inefficient when repeated [Re: [PATCH 00/11] Micro-optimizing lookup_object()]Thomas Rast, Aug 12, 2011
  15. Junio C HamanoAug 15, 2011

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.