Optimize construction of hash inputs