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

Avoid redundant HashMap.containsKey call in java.util.regex

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Fixed
    • Icon: P5 P5
    • 21
    • None
    • core-libs

      Pattern.namedGroups and Matcher.namedGroups contains only non-null values. It means instead of separate containsKey+get calls, we can use single HashMap.get call and then compare result with null.
      Result code is a bit simpler and faster.

      Affected methods:
      1. java.util.regex.Matcher#getMatchedGroupIndex
      2. java.util.regex.Pattern#escape
      3. java.util.regex.Matcher#appendExpandedReplacement

            aturbanov Andrey Turbanov
            aturbanov Andrey Turbanov
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: