Refactor conditional statements to switch expression in Dictionary class - #16313
Conversation
|
Why would we do this? We don't want to be making changes just for the sake of making changes. It looks as if you must be running some kind of bot that is generating automated code change PRs. For me, that is unwelcome. I don't have time to review endless trivial bot-generated PRs - also why are you calling me out by name? This isn't code I have any particular association with. It's generally not a good idea to invoke individuals without a good reason. I hope you'll take this criticism in a constructive spirit and devote your energy to meaningful contributions to this project - thanks! |
|
If we see in the code, there's already a TODO defined for improvement. I thought why not refactor and help. |
|
There is actually some value in this conversion since switch statements on strings should compile to faster code than a series of ifs - I'll merge this. |
|
Please run |
Yes, correct. There are 44 if-else statements in this code fragment.. |
|
It's compiled into a table lookup over the input string's hashCode. How it's optimized within hotspot - I've no idea. |
Ooh! I know this one. Initially it'll do a binary search over the valid hashCodes ( Hotspot can make a couple of possible optimizations to the |
Description
Fixes #16314