Skip to content
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

Move IScopedNode from SDK #228

Merged
merged 4 commits into from
Dec 13, 2023
Merged

Conversation

marcovisserFurore
Copy link
Member

Move the interface IScopedNod from the firely-net-sdk repo.

@marcovisserFurore
Copy link
Member Author

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@marcovisserFurore marcovisserFurore marked this pull request as ready for review December 12, 2023 16:05
public object Value => _adaptee.Value;

public IEnumerable<ITypedElement> Children(string? name = null) =>
_adaptee.Children(name).Select(n => new ScopedNodeToTypedElementAdapter(n));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If _adaptee is a ScopedNode, we don't need to wrap it I think, as ScopedNode already implements ITypedElement?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes we do have to cast it, because the constructor of TypedElementToIScopedNodeToAdapter needs a ScopedNode as an argument. When I skip the cast, the constructor will not work anymore.
Why not make the _adaptee of type ITypedElement you would say? When we do that we have to do the cast at the property public ScopedNode ScopedNode instead. So I chose for the casting at the Children() function.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But it is not a cast, we are creating lots of new objects, which I know by testing both increases GC load and slows down validation - so I want to make sure we really need this!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I change the class a bit. The field _adaptee is now of type ITypedElement and we have a private constructor that takes an ITypedElement. Doing so, we don't need the cast in children anymore. The cast moved to property ScopedNode.

Wrapping is still needed because this adapter implements IScopedNode. ScopedNode implements ITypedElement, but not IScopedNode.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I misread your comment. This about the ScopedNodeToTypedElementAdapter. I was talking about TypedElementToIScopedNodeToAdapter.

About ScopedNodeToTypedElementAdapter:

This adapter is only used by the extension method AsTypedElement. Looking at the implementation of this method we see:

public static ITypedElement AsTypedElement(this IScopedNode node) => node switch
{
    TypedElementToIScopedNodeToAdapter adapter => adapter.ScopedNode,
    ITypedElement ite => ite,
    _ => new ScopedNodeToTypedElementAdapter(node)
};

The first 2 cases already bypass the adapter. Only in rare cases the adapter is used. In fact, I ran all the tests and the adapter is never used!

…operty ScopedNode. This is better for the performance.
@ewoutkramer ewoutkramer merged commit 08e41a1 into develop Dec 13, 2023
2 checks passed
@ewoutkramer ewoutkramer deleted the feature/move-iscopednode-from-sdk branch December 13, 2023 13:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants