From: Linus Torvalds <torvalds@linux-foundation.org>
To: Jeff King <peff@peff.net>
Cc: Git Mailing List <git@vger.kernel.org>,
Paul Mackerras <paulus@samba.org>,
Junio C Hamano <junkio@cox.net>
Subject: Re: gitk problems: can't unset "idinlist(...)"
Date: Fri, 20 Jul 2007 23:47:24 -0700 (PDT) [thread overview]
Message-ID: <alpine.LFD.0.999.0707202335570.27249@woody.linux-foundation.org> (raw)
In-Reply-To: <20070721062448.GA8722@coredump.intra.peff.net>
On Sat, 21 Jul 2007, Jeff King wrote:
>
> By which I mean you can keep the 'for' loop, since in either case we are
> always reading p->next (if we skip, then we set *pp to p->next anyway,
> and if we don't, then pp becomes a pointer to p->next).
>
> So this is a more readable patch which I believe is equivalent.
Fair enough, that also works.
Anyway, just because this is actually something I've noticed a lot of
people do wrong, I actually do tend to think that when you traverse a
singly-linked list and remove entries, you should *never* traverse the
list itself, you should only ever traverse the "pointer to the pointer".
So the difference between your version and mine is that the
while ((p = *pp) != NULL)
model really only has one single "iterator variable": "pp". Which makes it
a lot easier to think about and avoid problems.
In contrast, your for-loop actually keeps track of *two* independent
variables, the "tail pointer of the list we're building up" (pp) and the
"head pointer of the old list we're traversing" (p).
Does it work? Yes. But I tend to prefer the "there's a single list" model,
where you just remove entries as you traverse it through a single indirect
pointer.
They're certainly equivalent, but slightly different mindsets. I at least
personally find the "single pointer" less likely to have problems, because
you can never get out of sync (which was basically exactly the problem
that Junio's code had), because there is nothing to get out of sync _with_
when you just have a single main iterator variable.
Linus
next prev parent reply other threads:[~2007-07-21 6:47 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-07-20 23:05 gitk problems: can't unset "idinlist(...)" Linus Torvalds
2007-07-21 5:09 ` Jeff King
2007-07-21 5:53 ` Linus Torvalds
2007-07-21 5:56 ` Junio C Hamano
2007-07-21 5:59 ` Jeff King
2007-07-21 6:06 ` Jeff King
2007-07-21 6:11 ` Linus Torvalds
2007-07-21 6:18 ` Jeff King
2007-07-21 6:24 ` Jeff King
2007-07-21 6:47 ` Linus Torvalds [this message]
2007-07-21 6:54 ` Jeff King
2007-07-21 9:32 ` pointer to pointer (was: gitk problems: can't unset "idinlist(...)") David Kastrup
2007-07-21 9:44 ` pointer to pointer David Kastrup
2007-07-21 6:34 ` gitk problems: can't unset "idinlist(...)" Linus Torvalds
2007-07-21 11:42 ` Paul Mackerras
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=alpine.LFD.0.999.0707202335570.27249@woody.linux-foundation.org \
--to=torvalds@linux-foundation.org \
--cc=git@vger.kernel.org \
--cc=junkio@cox.net \
--cc=paulus@samba.org \
--cc=peff@peff.net \
/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