CORDA-3322 - improve sha256 hashcode performance (#5592)

This commit is contained in:
Tudor Malene 2019-10-15 16:18:34 +01:00 committed by Rick Parker
parent 1ceb7ecd4f
commit 62a5485107

View File

@ -7,6 +7,7 @@ import net.corda.core.serialization.CordaSerializable
import net.corda.core.utilities.OpaqueBytes
import net.corda.core.utilities.parseAsHex
import net.corda.core.utilities.toHexString
import java.nio.ByteBuffer
import java.security.MessageDigest
/**
@ -21,6 +22,17 @@ sealed class SecureHash(bytes: ByteArray) : OpaqueBytes(bytes) {
init {
require(bytes.size == 32) { "Invalid hash size, must be 32 bytes" }
}
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (javaClass != other?.javaClass) return false
if (!super.equals(other)) return false
return true
}
// This is an efficient hashCode, because there is no point in performing a hash calculation on a cryptographic hash.
// It just takes the first 4 bytes and transforms them into an Int.
override fun hashCode() = ByteBuffer.wrap(bytes).int
}
/**