[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20241216172936.3223273e@kernel.org>
Date: Mon, 16 Dec 2024 17:29:36 -0800
From: Jakub Kicinski <kuba@...nel.org>
To: Petr Machata <petrm@...dia.com>
Cc: <davem@...emloft.net>, <netdev@...r.kernel.org>, <edumazet@...gle.com>,
<pabeni@...hat.com>, <shuah@...nel.org>, <linux-kselftest@...r.kernel.org>
Subject: Re: [PATCH net 5/5] selftests: net-drv: stats: sanity check netlink
dumps
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..
Powered by blists - more mailing lists