Optimize Strings.equal (#4262)

Co-authored-by: Hadrien Croubois <hadrien.croubois@gmail.com>
This commit is contained in:
Igor Żuk
2023-06-06 02:37:12 +02:00
committed by GitHub
parent ffceb3cd98
commit 253bfa68c2
2 changed files with 6 additions and 1 deletions

View File

@ -0,0 +1,5 @@
---
'openzeppelin-solidity': patch
---
Optimize `Strings.equal`

View File

@ -80,6 +80,6 @@ library Strings {
* @dev Returns true if the two strings are equal. * @dev Returns true if the two strings are equal.
*/ */
function equal(string memory a, string memory b) internal pure returns (bool) { function equal(string memory a, string memory b) internal pure returns (bool) {
return keccak256(bytes(a)) == keccak256(bytes(b)); return bytes(a).length == bytes(b).length && keccak256(bytes(a)) == keccak256(bytes(b));
} }
} }