mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-28 07:14:30 +02:00
8305785: Avoid redundant HashMap.containsKey call in java.util.regex
Reviewed-by: stsypanov, jpai
This commit is contained in:
parent
8011ba74a2
commit
6b65e5754c
2 changed files with 10 additions and 7 deletions
|
@ -1070,10 +1070,11 @@ public final class Matcher implements MatchResult {
|
|||
throw new IllegalArgumentException(
|
||||
"capturing group name {" + gname +
|
||||
"} starts with digit character");
|
||||
if (!namedGroups().containsKey(gname))
|
||||
Integer number = namedGroups().get(gname);
|
||||
if (number == null)
|
||||
throw new IllegalArgumentException(
|
||||
"No group with name {" + gname + "}");
|
||||
refNum = namedGroups().get(gname);
|
||||
refNum = number;
|
||||
cursor++;
|
||||
} else {
|
||||
// The first number is always a group
|
||||
|
@ -1805,9 +1806,10 @@ public final class Matcher implements MatchResult {
|
|||
int getMatchedGroupIndex(String name) {
|
||||
Objects.requireNonNull(name, "Group name");
|
||||
checkMatch();
|
||||
if (!namedGroups().containsKey(name))
|
||||
Integer number = namedGroups().get(name);
|
||||
if (number == null)
|
||||
throw new IllegalArgumentException("No group with name <" + name + ">");
|
||||
return namedGroups().get(name);
|
||||
return number;
|
||||
}
|
||||
|
||||
private void checkGroup(int group) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue