Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Interesting micro-optimizations... For example the use of lookup tables and nested switches in uri.rs and method.rs.

Is this common practice in Rust? Shouldn't the compiler be smart enough to do that for you? Such code seems quite sensitive to typos.



I don't think the lookup tables is a micro-optimization. They're both clear and fast in this case (I can't think of a more clear alternative, just of a less verbose one). The "switches" are actually pattern matching, a very powerful feature of Rust. I'm not sure about nesting them being a micro-optimization either. I think it's also a choice that is both readable and fast. Can a more experienced Rust code shed light?


This uses pattern matching, the compiler will verify that all options exists and that the coverage of the enum is complete.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: