Open
Conversation
|
There was an error handling pipeline event 018f3cc4-a623-46cc-878d-73bfd5be29a3. |
7f0f8fc to
f4289d1
Compare
There was a problem hiding this comment.
Pull Request Overview
This PR refactors the element factory implementation to use structs and file-scoped namespaces for a slight performance boost.
- Converted ElementFactory from a class to a readonly struct and removed the generic Create() method.
- Updated ElementFactoryCollection to use a List instead of an array and applied file-scoped namespaces.
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/DocumentFormat.OpenXml.Framework/Framework/Metadata/ElementFactoryCollection.cs | Replaced array with List, updated sorting and binary search, and switched to a file-scoped namespace. |
| src/DocumentFormat.OpenXml.Framework/Framework/Metadata/ElementFactory.cs | Changed from a sealed class to a readonly struct and removed the generic Create() factory method. |
Comments suppressed due to low confidence (1)
src/DocumentFormat.OpenXml.Framework/Framework/Metadata/ElementFactoryCollection.cs:18
- Changing the constructor parameter from IEnumerable to List restricts the accepted input type; ensure that all call sites are updated to pass a List to prevent potential runtime issues.
public ElementFactoryCollection(List<ElementFactory> lookup)
Comment on lines
+10
to
+11
| internal readonly struct ElementFactory(OpenXmlSchemaType type, Func<OpenXmlElement> factory) | ||
| { |
There was a problem hiding this comment.
Changing ElementFactory from a class to a struct introduces value semantics that can lead to unintended copying; please verify that all consumers handle these semantics correctly and that removing the generic Create() method is intentional.
Suggested change
| internal readonly struct ElementFactory(OpenXmlSchemaType type, Func<OpenXmlElement> factory) | |
| { | |
| internal class ElementFactory | |
| { | |
| private readonly OpenXmlSchemaType type; | |
| private readonly Func<OpenXmlElement> factory; | |
| public ElementFactory(OpenXmlSchemaType type, Func<OpenXmlElement> factory) | |
| { | |
| this.type = type; | |
| this.factory = factory; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This helps a bit with performance:
Before
After