git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Jeff King <peff@peff.net>
To: Jens Lehmann <Jens.Lehmann@web.de>
Cc: Quint Guvernator <quintus.public@gmail.com>,
	Git Mailing List <git@vger.kernel.org>
Subject: Re: [PATCH] general style: replaces memcmp() with starts_with()
Date: Wed, 12 Mar 2014 14:00:26 -0400	[thread overview]
Message-ID: <20140312180026.GB7982@sigill.intra.peff.net> (raw)
In-Reply-To: <532097D0.4070909@web.de>

On Wed, Mar 12, 2014 at 06:22:24PM +0100, Jens Lehmann wrote:

> > Let me know if you still think the hunk should be dropped there.
> 
> Yes, I think so. That spot uses memcmp() because ce->name may
> not be 0-terminated. If that assumption isn't correct, it should
> be replaced with a plain strcmp() instead (while also dropping
> the ce_namelen() comparison in the line above). But starts_with()
> points into the wrong direction there.

I think the length-check and memcmp is an optimization[1] here. But we
should be able to encapsulate that pattern and avoid magic numbers
entirely with something like mem_equals(). See my other response for
more details.

-Peff

[1] Getting rid of the magic number entirely means we have to call
    strlen(".gitmodules"), which seems like it is working against this
    optimization. But I think past experiments have shown that decent
    compilers will optimize strlen on a string literal to a constant, so
    as long as mem_equals is an inline, it should be equivalent.

  reply	other threads:[~2014-03-12 18:00 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-03-12 13:44 [PATCH] general style: replaces memcmp() with starts_with() Quint Guvernator
2014-03-12 13:51 ` Duy Nguyen
2014-03-12 14:06   ` Quint Guvernator
2014-03-13 16:05     ` Michael Haggerty
2014-03-14 16:32       ` Quint Guvernator
2014-03-12 15:47 ` Jens Lehmann
2014-03-12 16:46   ` Quint Guvernator
2014-03-12 17:22     ` Jens Lehmann
2014-03-12 18:00       ` Jeff King [this message]
2014-03-12 23:26       ` Duy Nguyen

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

  List information: http://vger.kernel.org/majordomo-info.html

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

  git send-email \
    --in-reply-to=20140312180026.GB7982@sigill.intra.peff.net \
    --to=peff@peff.net \
    --cc=Jens.Lehmann@web.de \
    --cc=git@vger.kernel.org \
    --cc=quintus.public@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.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).