Remove redundant dictionary lookup in XPathDocument (#85534)
authorStephen Toub <stoub@microsoft.com>
Fri, 28 Apr 2023 18:50:39 +0000 (14:50 -0400)
committerGitHub <noreply@github.com>
Fri, 28 Apr 2023 18:50:39 +0000 (14:50 -0400)
src/libraries/System.Private.Xml/src/System/Xml/XPath/XPathDocument.cs

index 5131a7d..f6f5b54 100644 (file)
@@ -398,15 +398,13 @@ namespace System.Xml.XPath
             Debug.Assert(pageElem[idxElem].NodeType == XPathNodeType.Element);
 
             // Check whether this element has any local namespaces
-            if (_mapNmsp == null || !_mapNmsp.ContainsKey(nodeRef))
+            if (_mapNmsp == null || !_mapNmsp.TryGetValue(nodeRef, out nodeRef))
             {
                 pageNmsp = null;
                 return 0;
             }
 
             // Yes, so return the page and index of the first local namespace node
-            nodeRef = _mapNmsp[nodeRef];
-
             pageNmsp = nodeRef.Page;
             return nodeRef.Index;
         }