3 ms·
That explains it, but shouldn't a switch with string or numerical constants (or an expression made up of constants) just be optimized away anyway?
by teruakohatu 4y ago
That explains it, but shouldn't a switch with string or numerical constants (or an expression made up of constants) just be optimized away anyway?
- jcfields 4y agoThe article quotes a Stack Overflow post with the conditions under which V8 will optimize the switch statement: > @LGB actually in V8 (JS engine used by google chrome) you need to jump through a lot of hoops to get switch case optimized: All the cases must be of same type. All the cases must either be string literals or 31-bit signed integer literals. And there must be less than 128 cases. And even after all those hoops, all you get is what you would have gotten with if-elses anyway (I.E. no jump tables or sth like that). True story. In the case of this emulator, it wasn’t being optimized because it had more than 128 cases.
- teruakohatu 4y ago> In the case of this emulator, it wasn’t being optimized because it had more than 128 cases. Now that makes sense. Thank you.