Remove some overhead from XmlNode.SelectSingleNode (#54299)
* Remove unnecessary cost from XmlNode.SelectSingleNode It's currently implemented by delegating to SelectSingleNodes and returning the first one. While the list is lazily-populated, this still entails creating an `XPathNodeList`, creating a `List<XmlNode>`, storing the enumerated into the list, and then returning the element from the list, which is then thrown away. With just a few lines, we can cut through all of that. * Make XPathScanner and XPathParser into structs No need for these to be allocated classes. They can just live on the stack where they're created. * Reduce ScanName overhead This shows up on the hot path of parsing the xpath expression. We can use a span to avoid bounds checking. * Avoid bounds check in NextChar NextChar is used by lots of routines to advance to the next character. We can streamline it to avoid the bounds check when indexing into the string. * Optimize SkipSpace for there not being any The typical case is there isn't any whitespace, so inline that fast check. This was showing up as a few percentage of a simple scenario.
Showing
想要评论请 注册 或 登录