Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 20 Apr 2016 08:48:07 +0800
From:      Marcelo Araujo <araujobsdport@gmail.com>
To:        John Baldwin <jhb@freebsd.org>
Cc:        "src-committers@freebsd.org" <src-committers@freebsd.org>,  "svn-src-all@freebsd.org" <svn-src-all@freebsd.org>,  "svn-src-head@freebsd.org" <svn-src-head@freebsd.org>
Subject:   Re: svn commit: r298247 - head/sbin/fdisk_pc98
Message-ID:  <CAOfEmZhofgYySTtMKAXo-Qkm8BRaOP8kzEfchdtPTH3T-0W-qQ@mail.gmail.com>
In-Reply-To: <4114217.PtcV9LDMal@ralph.baldwin.cx>
References:  <201604190446.u3J4kD9G050780@repo.freebsd.org> <4114217.PtcV9LDMal@ralph.baldwin.cx>

next in thread | previous in thread | raw e-mail | index | archive | help
2016-04-20 0:16 GMT+08:00 John Baldwin <jhb@freebsd.org>:

> On Tuesday, April 19, 2016 04:46:13 AM Marcelo Araujo wrote:
> > Author: araujo
> > Date: Tue Apr 19 04:46:13 2016
> > New Revision: 298247
> > URL: https://svnweb.freebsd.org/changeset/base/298247
> >
> > Log:
> >   Remove redundant parenthesis.
> >
> >   Submitted by:       pfg
> >   MFC after:  2 weeks.
>
> For this case, it might be better to remove numentries and use
> nitems() directly in the one place it is used.  I would probably
> even do this as a for-loop:
>
>         struct part_type *ptr;
>         int counter;
>
>         for (counter = 0, ptr = part_types; counter < nitems(part_types);
>             counter++, ptr++) {
>                 if (ptr->type == (type & 0x7f))
>                         return (ptr->name);
>         }
>         return ("unknown");
>
> If you renamed 'counter' to 'i' you could probably fit it all on one line.
>
> --
> John Baldwin
>

Hi John,

Yeap, make sense!
I came up with something like:

        struct  part_type *ptr = part_types;

        for (int i = 0; i < nitems(part_types); i++) {
                if (ptr->type == (type & 0x7f))
                        return (ptr->name);
                ptr++;
        }
        return("unknown");


What do you think?

Best,
-- 

-- 
Marcelo Araujo            (__)araujo@FreeBSD.org
\\\'',)http://www.FreeBSD.org <http://www.freebsd.org/>;   \/  \ ^
Power To Server.         .\. /_)



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAOfEmZhofgYySTtMKAXo-Qkm8BRaOP8kzEfchdtPTH3T-0W-qQ>