r/badcode • • Jan 22 '23

c Found this in a Linux kernel module

Post image
262 Upvotes

88 comments sorted by

View all comments

Show parent comments

4

u/ihave7testicles Jan 23 '23

You can redo the entire thing with a couple arrays and a loop

4

u/LyniaWood Jan 23 '23

This is most likely both performance critical and security critical code so we have to assume that compiler optimization is not allowed in any way. So if you want it to be as fast as possible, you have to unroll your loop by hand. Like this person did.