Actually replace keysort() not just one of its calls.

This has a performance impact, only for testing, not for
release, DO NOT merge into master. See discussion in #282.