Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 14 Oct 2017 14:03:05 -0400
From:      Mark Johnston <markj@FreeBSD.org>
To:        Matt Joras <mjoras@FreeBSD.org>
Cc:        "Ngie Cooper (yaneurabeya)" <yaneurabeya@gmail.com>, src-committers <src-committers@freebsd.org>, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   Re: svn commit: r324541 - in head: share/man/man9 sys/kern sys/sys
Message-ID:  <20171014180305.GA75158@raichu>
In-Reply-To: <a8093059-86ed-1582-a8fa-3c9c8800e213@FreeBSD.org>
References:  <201710112153.v9BLroeR007323@repo.freebsd.org> <365AD758-5761-4BD4-A80E-8EF2EA84EAAA@gmail.com> <a8093059-86ed-1582-a8fa-3c9c8800e213@FreeBSD.org>

next in thread | previous in thread | raw e-mail | index | archive | help
On Fri, Oct 13, 2017 at 10:36:26PM -0700, Matt Joras wrote:
> On 10/13/2017 22:12, Ngie Cooper (yaneurabeya) wrote:
> >> Modified: head/sys/kern/subr_unit.c
> >> ==============================================================================
> >> --- head/sys/kern/subr_unit.c	Wed Oct 11 20:36:22 2017	(r324540)
> >> +++ head/sys/kern/subr_unit.c	Wed Oct 11 21:53:50 2017	(r324541)
> >> @@ -366,6 +366,27 @@ delete_unrhdr(struct unrhdr *uh)
> >> 	Free(uh);
> >> }
> >>
> >> +void
> >> +clear_unrhdr(struct unrhdr *uh)
> >> +{
> >> +	struct unr *up, *uq;
> >> +
> >> +	KASSERT(TAILQ_EMPTY(&uh->ppfree),
> >> +	    ("unrhdr has postponed item for free"));
> >> +	up = TAILQ_FIRST(&uh->head);
> >> +	while (up != NULL) {
> > Could this be done with TAILQ_FOREACH_SAFE?
> > -Ngie
> 
> 
> Yes but it is arguably inferior to do so. This while loop is
> theoretically faster since there is no need to individually remove the
> elements when you intend to delete every element.

TAILQ_FOREACH_SAFE just fetches the next element at the beginning of
each loop iteration rather than at the end, same as the current
implementation of clear_unrhdr() does. There's no change to the code
generated by clang when I replace your loop with:

	TAILQ_FOREACH_SAFE(up, &uh->head, list, uq) {
		if (up->ptr != uh) {
			Free(up->ptr);
		}
		Free(up);
	}



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20171014180305.GA75158>