optimize the hashvalue calculation