A DESCRIPTION OF THE REQUEST :
After verifying if both strings have same length, method equals could compare the hash values of both strings before comparing character by character.
We could reduce the hash code compare on strings that yet have valid hash value i.e. != 0, or we could reduce it on strings where the equals method was invoked more than once, maybe controlled by a threshold.
JUSTIFICATION :
Comparing strings with same length and same characters at start, but different at there end would likely have different hash values, so comparing the hashes would be faster in case of negative equals() result.
After verifying if both strings have same length, method equals could compare the hash values of both strings before comparing character by character.
We could reduce the hash code compare on strings that yet have valid hash value i.e. != 0, or we could reduce it on strings where the equals method was invoked more than once, maybe controlled by a threshold.
JUSTIFICATION :
Comparing strings with same length and same characters at start, but different at there end would likely have different hash values, so comparing the hashes would be faster in case of negative equals() result.
- duplicates
-
JDK-6932808 (str) Tune equals() of String
-
- Open
-
- relates to
-
JDK-6992751 Optimized String.equals()
-
- Closed
-