Cache step_match results.

This offers a large speedup in larger test suites in which there are many
steps and some steps are reused many times.