Code sync towards a faster implementation. The key is to avoid virtual functions and inline as many functions as posible