Optimize calcPriority.

Suggested by @owainga.