svn commit: r324541 - in head: share/man/man9 sys/kern sys/sys

Mark Johnston markj at FreeBSD.org
Sat Oct 14 18:03:13 UTC 2017


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);
	}


More information about the svn-src-all mailing list