From: Jakub Kicinski <kuba@kernel.org>
To: Petr Machata <petrm@nvidia.com>
Cc: <davem@davemloft.net>, <netdev@vger.kernel.org>,
<edumazet@google.com>, <pabeni@redhat.com>, <shuah@kernel.org>,
<linux-kselftest@vger.kernel.org>
Subject: Re: [PATCH net 5/5] selftests: net-drv: stats: sanity check netlink dumps
Date: Mon, 16 Dec 2024 17:29:36 -0800 [thread overview]
Message-ID: <20241216172936.3223273e@kernel.org> (raw)
In-Reply-To: <877c7zvqe4.fsf@nvidia.com>
On Mon, 16 Dec 2024 11:53:58 +0100 Petr Machata wrote:
> > + if ifindex not in parsed:
> > + parsed[ifindex] = {"rx":[], "tx": []}
> > + parsed[ifindex][entry["queue-type"]].append(entry['queue-id'])
>
> BTW setdefault() exists for exactly these add-unless-already-exists
> scenarios:
>
> parsed_entry = parsed.setdefault(ifindex, {"rx":[], "tx": []})
> parsed_entry[entry["queue-type"]].append(entry['queue-id'])
>
> Sometimes this can be used to inline the whole expression, such as
> mydict.setdefault(key, []).append(value), but that would be unwieldy here.
Ack, I used setdefault() initially but it made the line too
incomprehensible. Too many things get indexed at once..
prev parent reply other threads:[~2024-12-17 1:29 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20241213152244.3080955-1-kuba@kernel.org>
2024-12-13 15:22 ` [PATCH net 3/5] selftests: net: support setting recv_size in YNL Jakub Kicinski
2024-12-13 21:45 ` Joe Damato
2024-12-16 10:37 ` Petr Machata
2024-12-13 15:22 ` [PATCH net 4/5] selftests: net-drv: queues: sanity check netlink dumps Jakub Kicinski
2024-12-13 21:47 ` Joe Damato
2024-12-16 10:46 ` Petr Machata
2024-12-13 15:22 ` [PATCH net 5/5] selftests: net-drv: stats: " Jakub Kicinski
2024-12-16 10:53 ` Petr Machata
2024-12-17 1:29 ` Jakub Kicinski [this message]
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=20241216172936.3223273e@kernel.org \
--to=kuba@kernel.org \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=linux-kselftest@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=petrm@nvidia.com \
--cc=shuah@kernel.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