From: Jeff King <peff@peff.net>
To: Junio C Hamano <gitster@pobox.com>
Cc: Johannes Schindelin <Johannes.Schindelin@gmx.de>, git@vger.kernel.org
Subject: Re: [PATCH] quote_path: fix collapsing of relative paths
Date: Mon, 3 Dec 2007 01:05:57 -0500 [thread overview]
Message-ID: <20071203060557.GA13011@coredump.intra.peff.net> (raw)
In-Reply-To: <7vabosqq1l.fsf@gitster.siamese.dyndns.org>
On Sun, Dec 02, 2007 at 09:56:54PM -0800, Junio C Hamano wrote:
> Somehow I feel it would be simpler and less error prone if you atually
> count to set len to the length if you got negative.
> [...]
> So perhaps this is easier to read?
Yes, I actually wrote the exact same patch but discarded it in favor of
what I sent, because I wanted a minimal change (and I assumed it had
been implemented that way to avoid the extra strlen call). But that is
just premature micro-optimization, and I think the version you posted is
much less subtle.
> The part that follows the patch, there is a line that subtracts a small
> number (off+1) from len --- while it won't have a wraparound issue, it
> feels a bit ugly to rely on the "magic -1" value to stay "magic
> negative" if small positive integers are subtracted from it.
I hadn't considered that, but another good reason to just set len in the
first place.
> Also the reason the updated condition to the while loop does not have to
> check NUL termination upon negative len is because both (prefix[off] !=
> NUL) and (prefix[off] == in[off]) are checked there, which some may find
> subtle.
Yes, I found it subtle, too, which is why I documented it in the commit
message. :)
> - if (len > 0)
> - strbuf_grow(out, len);
> - strbuf_setlen(out, 0);
> + if (len < 0)
> + len = strlen(in);
>
> + strbuf_grow(out, len);
> + strbuf_setlen(out, 0);
I wonder if this 'grow' is really all that useful, since we are now
going to overallocate in some cases. Perhaps we should just let strbuf
do its job and grow as necessary. But it likely doesn't matter either
way.
-Peff
next prev parent reply other threads:[~2007-12-03 6:06 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-12-03 5:30 [PATCH] quote_path: fix collapsing of relative paths Jeff King
2007-12-03 5:56 ` Junio C Hamano
2007-12-03 6:05 ` Jeff King [this message]
2007-12-03 12:32 ` Johannes Schindelin
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=20071203060557.GA13011@coredump.intra.peff.net \
--to=peff@peff.net \
--cc=Johannes.Schindelin@gmx.de \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.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 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 NNTP newsgroup(s).