It would be awesome if `when` expressions over a S...
# compiler
m
It would be awesome if
when
expressions over a String with plenty of constant cases could be optimized somehow, e.g. by using tableswitches for 1st & 2nd character (esp. if latin) or by using hashes. Right now such cases will just repeatedly call
equals
which can be much slower. For now I’m using a
HashMap
with
String
as key and a lambda as value but the lambdas will create a crazy amount of anonymous classes. I’ve also tried a
HashMap
to
Int
and then use the
Int
for the
when
expression but for whatever reason that was slower 😮 Prbl. because of boxing.
u
We do have an optimization for
when
over strings where we switch on the hash code, and then compare the string with one of the patterns with that hash code. It’s basically the same as in Java. Can you provide an example where it doesn’t work?
m
Ah I see it now! A tableswitch before the equals checks, great 🙂 I guess I’ve just overlooked it the first time, thanks!