Re: [PATCH net-next] rust: net::phy inline if expressions to improve read_status

From: Andrew Lunn

Date: Fri Sep 19 2025 - 08:54:59 EST


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.

Andrew