News for hackers. Stuff that matters.
Re:TinyVM: A lightweight, fast virtual machine in < 500 l... by windsurfer on Saturday July 02, 2011 @06:28PM (#2722577)
Why can't the compiler optimize this?
Re:TinyVM: A lightweight, fast virtual machine in < 500 l... by to3m on Saturday July 02, 2011 @06:54PM (#2722623)
Theoretically, it could do, at least in this case, I think? Very risky to rely on that though! I doubt compiler writers have people who haven't heard of the switch statement in mind when they decide which optimizations to put in.

(The "fast" branch uses a switch statement - I guess the author is going for minimum number of lines in this one? I'm not sure saving 2-3 lines compared to a squeezed-together switch statement is a great tradeoff, though. You could get better results by just putting everything in one source file. Easier deployment, too. I bet it wouldn't affect readability significantly.)

Re:TinyVM: A lightweight, fast virtual machine in < 500 l... by ori_b on Saturday July 02, 2011 @07:59PM (#2722691)
It can. However, this is a very uncommon pattern, so it's not worth trying very hard to detect. On top of that, I'd expect the compiler to bail after the pattern gets to a certain size.