-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Dispose XmlReaders in System.Xml.Xpath.XPathNavigator #103294
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1042,7 +1042,7 @@ public virtual bool CheckValidity(XmlSchemaSet schemas, ValidationEventHandler v | |
|
||
CheckValidityHelper validityTracker = new CheckValidityHelper(validationEventHandler, reader); | ||
validationEventHandler = new ValidationEventHandler(validityTracker.ValidationCallback); | ||
XmlReader validatingReader = GetValidatingReader(reader, schemas, validationEventHandler, schemaType, schemaElement, schemaAttribute); | ||
using XmlReader validatingReader = GetValidatingReader(reader, schemas, validationEventHandler, schemaType, schemaElement, schemaAttribute); | ||
|
||
while (validatingReader.Read()) | ||
; | ||
|
@@ -1291,7 +1291,7 @@ public virtual XmlWriter ReplaceRange(XPathNavigator lastSiblingToReplace) | |
|
||
public virtual void ReplaceSelf(string newNode) | ||
{ | ||
XmlTextReader reader = CreateContextReader(newNode, false); | ||
using XmlTextReader reader = CreateContextReader(newNode, false); | ||
ReplaceSelf(reader); | ||
} | ||
|
||
|
@@ -1306,16 +1306,15 @@ public virtual void ReplaceSelf(XmlReader newNode) | |
{ | ||
throw new InvalidOperationException(SR.Xpn_BadPosition); | ||
} | ||
XmlWriter writer = ReplaceRange(this); | ||
using XmlWriter writer = ReplaceRange(this); | ||
BuildSubtree(newNode, writer); | ||
writer.Close(); | ||
} | ||
|
||
public virtual void ReplaceSelf(XPathNavigator newNode) | ||
{ | ||
ArgumentNullException.ThrowIfNull(newNode); | ||
|
||
XmlReader reader = newNode.CreateReader(); | ||
using XmlReader reader = newNode.CreateReader(); | ||
ReplaceSelf(reader); | ||
} | ||
|
||
|
@@ -1444,17 +1443,16 @@ public virtual string InnerXml | |
|
||
public virtual void AppendChild(string newChild) | ||
{ | ||
XmlReader reader = CreateContextReader(newChild, true); | ||
using XmlReader reader = CreateContextReader(newChild, true); | ||
AppendChild(reader); | ||
} | ||
|
||
public virtual void AppendChild(XmlReader newChild) | ||
{ | ||
ArgumentNullException.ThrowIfNull(newChild); | ||
|
||
XmlWriter writer = AppendChild(); | ||
using XmlWriter writer = AppendChild(); | ||
BuildSubtree(newChild, writer); | ||
writer.Close(); | ||
} | ||
|
||
public virtual void AppendChild(XPathNavigator newChild) | ||
|
@@ -1465,23 +1463,22 @@ public virtual void AppendChild(XPathNavigator newChild) | |
{ | ||
throw new InvalidOperationException(SR.Xpn_BadPosition); | ||
} | ||
XmlReader reader = newChild.CreateReader(); | ||
using XmlReader reader = newChild.CreateReader(); | ||
AppendChild(reader); | ||
} | ||
|
||
public virtual void PrependChild(string newChild) | ||
{ | ||
XmlReader reader = CreateContextReader(newChild, true); | ||
using XmlReader reader = CreateContextReader(newChild, true); | ||
PrependChild(reader); | ||
} | ||
|
||
public virtual void PrependChild(XmlReader newChild) | ||
{ | ||
ArgumentNullException.ThrowIfNull(newChild); | ||
|
||
XmlWriter writer = PrependChild(); | ||
using XmlWriter writer = PrependChild(); | ||
BuildSubtree(newChild, writer); | ||
writer.Close(); | ||
} | ||
|
||
public virtual void PrependChild(XPathNavigator newChild) | ||
|
@@ -1492,23 +1489,22 @@ public virtual void PrependChild(XPathNavigator newChild) | |
{ | ||
throw new InvalidOperationException(SR.Xpn_BadPosition); | ||
} | ||
XmlReader reader = newChild.CreateReader(); | ||
using XmlReader reader = newChild.CreateReader(); | ||
PrependChild(reader); | ||
} | ||
|
||
public virtual void InsertBefore(string newSibling) | ||
{ | ||
XmlReader reader = CreateContextReader(newSibling, false); | ||
using XmlReader reader = CreateContextReader(newSibling, false); | ||
InsertBefore(reader); | ||
} | ||
|
||
public virtual void InsertBefore(XmlReader newSibling) | ||
{ | ||
ArgumentNullException.ThrowIfNull(newSibling); | ||
|
||
XmlWriter writer = InsertBefore(); | ||
using XmlWriter writer = InsertBefore(); | ||
BuildSubtree(newSibling, writer); | ||
writer.Close(); | ||
} | ||
|
||
public virtual void InsertBefore(XPathNavigator newSibling) | ||
|
@@ -1519,23 +1515,22 @@ public virtual void InsertBefore(XPathNavigator newSibling) | |
{ | ||
throw new InvalidOperationException(SR.Xpn_BadPosition); | ||
} | ||
XmlReader reader = newSibling.CreateReader(); | ||
using XmlReader reader = newSibling.CreateReader(); | ||
InsertBefore(reader); | ||
} | ||
|
||
public virtual void InsertAfter(string newSibling) | ||
{ | ||
XmlReader reader = CreateContextReader(newSibling, false); | ||
using XmlReader reader = CreateContextReader(newSibling, false); | ||
InsertAfter(reader); | ||
} | ||
|
||
public virtual void InsertAfter(XmlReader newSibling) | ||
{ | ||
ArgumentNullException.ThrowIfNull(newSibling); | ||
|
||
XmlWriter writer = InsertAfter(); | ||
using XmlWriter writer = InsertAfter(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are any of these changes actually improving things? It's possible they could lead to performance regressions, as these are mostly methods that could otherwise be inlined (in particular with dynamic PGO), and now with the exception handling they likely won't be. I'd prefer to close this PR unless it's actually solving a real run-time problem. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I have no data to make that claim.
Fair enough! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, thanks |
||
BuildSubtree(newSibling, writer); | ||
writer.Close(); | ||
} | ||
|
||
public virtual void InsertAfter(XPathNavigator newSibling) | ||
|
@@ -1546,7 +1541,7 @@ public virtual void InsertAfter(XPathNavigator newSibling) | |
{ | ||
throw new InvalidOperationException(SR.Xpn_BadPosition); | ||
} | ||
XmlReader reader = newSibling.CreateReader(); | ||
using XmlReader reader = newSibling.CreateReader(); | ||
InsertAfter(reader); | ||
} | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.