From: Thorsten Blum <thorsten.blum@linux.dev>
To: Andrew Lunn <andrew@lunn.ch>
Cc: "FUJITA Tomonori" <fujita.tomonori@gmail.com>,
"Trevor Gross" <tmgross@umich.edu>,
"Heiner Kallweit" <hkallweit1@gmail.com>,
"Russell King" <linux@armlinux.org.uk>,
"David S. Miller" <davem@davemloft.net>,
"Eric Dumazet" <edumazet@google.com>,
"Jakub Kicinski" <kuba@kernel.org>,
"Paolo Abeni" <pabeni@redhat.com>,
"Miguel Ojeda" <ojeda@kernel.org>,
"Alex Gaynor" <alex.gaynor@gmail.com>,
"Boqun Feng" <boqun.feng@gmail.com>,
"Gary Guo" <gary@garyguo.net>,
"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
"Benno Lossin" <lossin@kernel.org>,
"Andreas Hindborg" <a.hindborg@kernel.org>,
"Alice Ryhl" <aliceryhl@google.com>,
"Danilo Krummrich" <dakr@kernel.org>,
netdev@vger.kernel.org, rust-for-linux@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH net-next] rust: net::phy inline if expressions to improve read_status
Date: Fri, 19 Sep 2025 15:30:00 +0200 [thread overview]
Message-ID: <A17B492B-0EAD-4CCE-9889-6D559401D3D3@linux.dev> (raw)
In-Reply-To: <d1fe6fa4-da50-4899-8e2c-0721851c4e0d@lunn.ch>
On 19. Sep 2025, at 14:54, Andrew Lunn wrote:
> On Fri, Sep 19, 2025 at 01:20:08PM +0200, Thorsten Blum wrote:
>> Inline the if expressions for dev.set_speed() and dev.set_duplex() to
>> improve read_status(). This ensures dev.set_speed() is called only once
>
> What is the issue of calling it twice, or 42 times??
>
>> and allows us to remove the local variable 'duplex'.
>
> And what is wrong with local variables?
>
> And did you disassemble the code? What is the compiler actually doing?
> Does it actually have a stack variable, or is it just a register? Does
> the optimiser end up with just a single call to set_speed()?
>
> This is slow path code. It gets called at most once per
> second. Performance does not matter. Which means readability has much
> higher preference. And i find the older version much easier to read.
There's obviously nothing wrong with local variables. This patch is not
about performance improvements, but writing consistent and idiomatic
Rust code.
Currently, dev.set_duplex() uses a local variable and is called once,
whereas dev.set_speed() doesn't use a local variable and is called
twice. This is just a cleanup patch using idiomatic (afaik) Rust code.
Thanks,
Thorsten
next prev parent reply other threads:[~2025-09-19 13:32 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-19 11:20 [PATCH net-next] rust: net::phy inline if expressions to improve read_status Thorsten Blum
2025-09-19 12:54 ` Andrew Lunn
2025-09-19 13:30 ` Thorsten Blum [this message]
2025-09-19 15:16 ` Andrew Lunn
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=A17B492B-0EAD-4CCE-9889-6D559401D3D3@linux.dev \
--to=thorsten.blum@linux.dev \
--cc=a.hindborg@kernel.org \
--cc=alex.gaynor@gmail.com \
--cc=aliceryhl@google.com \
--cc=andrew@lunn.ch \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun.feng@gmail.com \
--cc=dakr@kernel.org \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=fujita.tomonori@gmail.com \
--cc=gary@garyguo.net \
--cc=hkallweit1@gmail.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@armlinux.org.uk \
--cc=lossin@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=ojeda@kernel.org \
--cc=pabeni@redhat.com \
--cc=rust-for-linux@vger.kernel.org \
--cc=tmgross@umich.edu \
/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