From: "Morten Brørup" <mb@smartsharesystems.com>
To: "Bruce Richardson" <bruce.richardson@intel.com>,
"David Marchand" <david.marchand@redhat.com>
Cc: <dev@dpdk.org>, "Ciara Power" <ciara.power@intel.com>
Subject: RE: [PATCH] telemetry: support boolean type
Date: Wed, 19 Oct 2022 20:08:53 +0200 [thread overview]
Message-ID: <98CBD80474FA8B44BF855DF32C47DC35D8741A@smartserver.smartshare.dk> (raw)
In-Reply-To: <Y1AqN9NnjBjpTsf+@bricha3-MOBL.ger.corp.intel.com>
> From: Bruce Richardson [mailto:bruce.richardson@intel.com]
> Sent: Wednesday, 19 October 2022 18.48
>
> On Wed, Oct 19, 2022 at 04:28:58PM +0200, David Marchand wrote:
> > On Wed, Oct 19, 2022 at 3:48 PM Bruce Richardson
> > <bruce.richardson@intel.com> wrote:
> > >
> > > On Wed, Oct 19, 2022 at 09:37:02AM +0200, David Marchand wrote:
> > > > Add the boolean type RTE_TEL_BOOL_VAL for values in arrays and
> dicts.
> > > >
> > > > Signed-off-by: David Marchand <david.marchand@redhat.com>
> > > > ---
[...]
> > > > +/* Appends a boolean into the JSON array in the provided buffer.
> */
> > > > +static inline int
> > > > +rte_tel_json_add_array_bool(char *buf, const int len, const int
> used,
> > > > + bool val)
> > > > +{
> > > > + int ret, end = used - 1; /* strip off final delimiter */
> > > > + if (used <= 2) /* assume empty, since minimum is '[]' */
> > > > + return __json_snprintf(buf, len, "[%s]",
> > > > + val ? "true" : "false");
> > > > +
> > > > + ret = __json_snprintf(buf + end, len - end, ",%s]",
> > > > + val ? "true" : "false");
> > >
> > > Wonder if it's worthwhile doing a macro for this conditional, since
> the
> > > same ternary-operator snippet appears 4 times in this code.
> >
> > Err, naming it would be hard and I don't see for now how we could
> reuse it.
> >
> Yes, and I see Morten has objected from a readability perspective, so
> keeping as-is is fine.
>
> One final suggestion though might be to have an array with the strings
> as so:
>
> const char *bool_str[2] = { "false", "true" };
>
> and then in the code use "bool_str[val]" in place of ternary operator.
I don't consider that more readable than the original.
> (From a quick check with godbolt is looks like bool params are clamped
> to 0
> or 1 on function call, but if we want to be paranoid, we can lookup
> based
> on [!!val])
>
> However, ok to keep code as-is for this too.
Thank you, yes, please.
>
> /Bruce
next prev parent reply other threads:[~2022-10-19 18:08 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-19 7:37 David Marchand
2022-10-19 8:13 ` Morten Brørup
2022-10-19 13:47 ` Bruce Richardson
2022-10-19 14:18 ` Morten Brørup
2022-10-19 14:28 ` David Marchand
2022-10-19 16:47 ` Bruce Richardson
2022-10-19 18:08 ` Morten Brørup [this message]
2022-10-20 9:54 ` Power, Ciara
2022-10-20 11:48 ` David Marchand
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=98CBD80474FA8B44BF855DF32C47DC35D8741A@smartserver.smartshare.dk \
--to=mb@smartsharesystems.com \
--cc=bruce.richardson@intel.com \
--cc=ciara.power@intel.com \
--cc=david.marchand@redhat.com \
--cc=dev@dpdk.org \
/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).