[Compiler] Improve algorithm for short symbol name

Authored by akreuzkamp.