Optimized long hash function.