From b0173340c6b5fb330f5ea22504389fc6c5367f14 Mon Sep 17 00:00:00 2001 From: Taylor Blau Date: Sun, 29 Aug 2021 22:48:57 -0400 Subject: builtin/pack-objects.c: remove duplicate hash lookup In the original code from 08cdfb1337 (pack-objects --keep-unreachable, 2007-09-16), we add each object to the packing list with type `obj->type`, where `obj` comes from `lookup_unknown_object()`. Unless we had already looked up and parsed the object, this will be `OBJ_NONE`. That's fine, since oe_set_type() sets the type_valid bit to '0', and we determine the real type later on. So the only thing we need from the object lookup is access to the `flags` field so that we can mark that we've added the object with `OBJECT_ADDED` to avoid adding it again (we can just pass `OBJ_NONE` directly instead of grabbing it from the object). But add_object_entry() already rejects duplicates! This has been the behavior since 7a979d99ba (Thin pack - create packfile with missing delta base., 2006-02-19), but 08cdfb1337 didn't take advantage of it. Moreover, to do the OBJECT_ADDED check, we have to do a hash lookup in `obj_hash`. So we can drop the lookup_unknown_object() call completely, *and* the OBJECT_ADDED flag, too, since the spot we're touching here is the only location that checks it. In the end, we perform the same number of hash lookups, but with the added bonus that we don't waste memory allocating an OBJ_NONE object (if we were traversing, we'd need it eventually, but the whole point of this code path is not to traverse). Signed-off-by: Taylor Blau Signed-off-by: Junio C Hamano --- object.h | 1 - 1 file changed, 1 deletion(-) (limited to 'object.h') diff --git a/object.h b/object.h index 3b38c9cc98..549f2d256b 100644 --- a/object.h +++ b/object.h @@ -75,7 +75,6 @@ struct object_array { * builtin/fsck.c: 0--3 * builtin/gc.c: 0 * builtin/index-pack.c: 2021 - * builtin/pack-objects.c: 20 * builtin/reflog.c: 10--12 * builtin/show-branch.c: 0-------------------------------------------26 * builtin/unpack-objects.c: 2021 -- cgit v1.2.3 From 9865b6e6a4ca1e895fd473c827cf1822f3bd8249 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=86var=20Arnfj=C3=B6r=C3=B0=20Bjarmason?= Date: Mon, 27 Sep 2021 14:54:25 +0200 Subject: *.[ch] *_INIT macros: use { 0 } for a "zero out" idiom MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In C it isn't required to specify that all members of a struct are zero'd out to 0, NULL or '\0', just providing a "{ 0 }" will accomplish that. Let's also change code that provided N zero'd fields to just provide one, and change e.g. "{ NULL }" to "{ 0 }" for consistency. I.e. even if the first member is a pointer let's use "0" instead of "NULL". The point of using "0" consistently is to pick one, and to not have the reader wonder why we're not using the same pattern everywhere. Signed-off-by: Ævar Arnfjörð Bjarmason Signed-off-by: Junio C Hamano --- object.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'object.h') diff --git a/object.h b/object.h index 549f2d256b..cb556ab775 100644 --- a/object.h +++ b/object.h @@ -55,7 +55,7 @@ struct object_array { } *objects; }; -#define OBJECT_ARRAY_INIT { 0, 0, NULL } +#define OBJECT_ARRAY_INIT { 0 } /* * object flag allocation: -- cgit v1.2.3