Trying to remove a performance problem indicated by #1001735.

The code is a bit uglier, but it should perform much better. A
small price to pay if this actually fixes Scala-IDE #1001735.