Calculate checksum only if necessary (#6129)