From: Junio C Hamano Date: Tue, 23 Aug 2016 16:28:17 GMT Subject: Re: [PATCH v8 7/8] cache: add empty_tree_oid object Message-ID: In-Reply-To: <20160819205806.vxzzgphqf4lgdor7@sigill.intra.peff.net> Jeff King writes: > I suspect we need more than just the "is_empty" query. At least for the > blob case, we do hashcpy() it into a struct (which should eventually > become oidcpy). The empty-tree case even more so, as we pass it to > random functions like lookup_tree(). > > Our EMPTY_TREE_SHA1_BIN_LITERAL effectively ends up as a singleton > in-core, too; it's just handled transparently by the compiler, since > it's a literal. This effectively gives us _two_ singletons. We could do: > > const struct object_id empty_blob_oid = { > "\xe6\x9d\xe2\x9b\xb2\xd1\xd6\x43\x4b\x8b" > "\x29\xae\x77\x5a\xd8\xc2\xe4\x8c\x53\x91" > }; > #define EMPTY_BLOB_SHA1_BIN (empty_blob_oid.hash) > > It's possible the use of an actual string literal lets the compiler do > more optimizations, but I'd doubt it matters in practice. Probably it is > just sticking that literal somewhere in BSS and filling in the pointer > to it. Makes sense; thanks.