Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit 55e6f2d

Browse files
committed
Merge pull request #2677 from James-Ko/tgval
Replace ContainsKey with TryGetValue in Regex
2 parents 1f94e2c + 97d7431 commit 55e6f2d

File tree

1 file changed

+3
-5
lines changed
  • src/System.Text.RegularExpressions/src/System/Text/RegularExpressions

1 file changed

+3
-5
lines changed

src/System.Text.RegularExpressions/src/System/Text/RegularExpressions/Regex.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -362,10 +362,8 @@ public String GroupNameFromNumber(int i)
362362
{
363363
if (_caps != null)
364364
{
365-
if (!_caps.ContainsKey(i))
365+
if (!_caps.TryGetValue(i, out i))
366366
return String.Empty;
367-
368-
i = _caps[i];
369367
}
370368

371369
if (i >= 0 && i < _capslist.Length)
@@ -395,10 +393,10 @@ public int GroupNumberFromName(String name)
395393
// look up name if we have a hashtable of names
396394
if (_capnames != null)
397395
{
398-
if (!_capnames.ContainsKey(name))
396+
if (!_capnames.TryGetValue(name, out result))
399397
return -1;
400398

401-
return _capnames[name];
399+
return result;
402400
}
403401

404402
// convert to an int if it looks like a number

0 commit comments

Comments
 (0)