Simplify switch?
veorq opened this issue · 3 comments
veorq commented
from https://twitter.com/vmload/status/1552613272532172801
Switch case could be simplified to this?
for (i = 1; i <= left; i++) {
b |= ((uint64_t)ni[i - 1]) << (8 * (i - 1));
}
demerphq commented
On Thu, 28 Jul 2022 at 13:16, Jean-Philippe Aumasson < ***@***.***> wrote:
from https://twitter.com/vmload/status/1552613272532172801
Switch case could be simplified to this?
for (i = 1; i <= left; i++) {
b |= ((uint64_t)ni[i - 1]) << (8 * (i - 1));
}
FWIW that doesn't look like a simplification to me. The switch fallthrough
trick is so common, and elegant, for this task that anyone remotely exposed
to reading blocks will have encountered it. The code above I have to think
about to understand that it is correct, and maybe even run it, whereas the
switch is obviously correct at a glance. And the switch is more
efficient without relying on the compiler to optimize it. I guess it really
depends on how you define "simplify".
Yves
…--
perl -Mre=debug -e "/just|another|perl|hacker/"
jedisct1 commented
I agree that it doesn't simplify anything. The code is shorter, but less readable.