Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6912520

String#equals(Object) should benefit from hash code

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Duplicate
    • Icon: P5 P5
    • None
    • 7
    • core-libs
    • x86
    • windows_xp

      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.

            Unassigned Unassigned
            ndcosta Nelson Dcosta (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: