All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jeff King <peff@peff.net>
To: Junio C Hamano <gitster@pobox.com>
Cc: Jacob Keller <jacob.e.keller@intel.com>,
	git@vger.kernel.org, Stefan Beller <stefanbeller@gmail.com>,
	Johannes Sixt <j6t@kdbg.org>,
	Jacob Keller <jacob.keller@gmail.com>
Subject: Re: [PATCH v8 7/8] cache: add empty_tree_oid object
Date: Fri, 19 Aug 2016 16:58:06 -0400	[thread overview]
Message-ID: <20160819205806.vxzzgphqf4lgdor7@sigill.intra.peff.net> (raw)
In-Reply-To: <xmqqfuq01oww.fsf@gitster.mtv.corp.google.com>

On Fri, Aug 19, 2016 at 01:31:27PM -0700, Junio C Hamano wrote:

> Jacob Keller <jacob.e.keller@intel.com> writes:
> 
> > From: Jacob Keller <jacob.keller@gmail.com>
> >
> > Add an empty_tree_oid object which can be used in place of
> > EMPTY_TREE_SHA1_BIN_LITERAL for code which is being converted to struct
> > object_id.
> 
> How widely do you envision the users of this symbol would be spread
> across the entire codebase?  I am debating myself if we need a
> singleton in-core copy like this (if we end up referring to it from
> everywhere), or we only need one level higher abstraction,
> e.g. "is_empty_tree_oid()" helper (in which case I do not think we
> even need a singleton; just imitate how is_empty_blob_sha1() is
> implemented).

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.

-Peff

  parent reply	other threads:[~2016-08-19 20:58 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-19  0:00 [PATCH v8 0/8] submodule show inline diff Jacob Keller
2016-08-19  0:00 ` [PATCH v8 1/8] diff.c: remove output_prefix_length field Jacob Keller
2016-08-19  0:00 ` [PATCH v8 2/8] graph: add support for --line-prefix on all graph-aware output Jacob Keller
2016-08-19  0:00 ` [PATCH v8 3/8] diff: prepare for additional submodule formats Jacob Keller
2016-08-19 19:49   ` Junio C Hamano
2016-08-19  0:00 ` [PATCH v8 4/8] submodule: allow add_submodule_odb to work even if path is not checked out Jacob Keller
2016-08-19 20:06   ` Junio C Hamano
2016-08-19 20:32     ` Jacob Keller
2016-08-19 21:11       ` Junio C Hamano
2016-08-19 22:00         ` Jacob Keller
2016-08-19 22:26           ` Junio C Hamano
2016-08-19 23:25             ` Jacob Keller
2016-08-19  0:00 ` [PATCH v8 5/8] submodule: convert show_submodule_summary to use struct object_id * Jacob Keller
2016-08-19 20:12   ` Junio C Hamano
2016-08-19  0:00 ` [PATCH v8 6/8] submodule: refactor show_submodule_summary with helper function Jacob Keller
2016-08-19 20:24   ` Junio C Hamano
2016-08-19 20:33     ` Jacob Keller
2016-08-19  0:00 ` [PATCH v8 7/8] cache: add empty_tree_oid object Jacob Keller
2016-08-19 20:31   ` Junio C Hamano
2016-08-19 20:35     ` Jacob Keller
2016-08-19 20:50       ` Junio C Hamano
2016-08-19 21:14         ` Junio C Hamano
2016-08-19 22:02           ` Jacob Keller
2016-08-19 20:58     ` Jeff King [this message]
2016-08-23 16:28       ` Junio C Hamano
2016-08-19  0:00 ` [PATCH v8 8/8] diff: teach diff to display submodule difference with an inline diff Jacob Keller
2016-08-19 21:52   ` Junio C Hamano
2016-08-19 22:03     ` Jacob Keller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20160819205806.vxzzgphqf4lgdor7@sigill.intra.peff.net \
    --to=peff@peff.net \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=j6t@kdbg.org \
    --cc=jacob.e.keller@intel.com \
    --cc=jacob.keller@gmail.com \
    --cc=stefanbeller@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.