-
Notifications
You must be signed in to change notification settings - Fork 557
Use structs for element factory #1844
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
base: main
Are you sure you want to change the base?
Conversation
There was an error handling pipeline event 018f3cc4-a623-46cc-878d-73bfd5be29a3. |
7f0f8fc
to
f4289d1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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)
internal readonly struct ElementFactory(OpenXmlSchemaType type, Func<OpenXmlElement> factory) | ||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
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; | |
} |
Copilot uses AI. Check for mistakes.
This helps a bit with performance:
Before
After