Don't use std::function for hot paths.

std::function is a virtual function call, this was causing about
1000 cache misses for a single test run