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

Improve variable initialization #2223

Merged
merged 4 commits into from
Jun 9, 2023
Merged

Conversation

jnyrup
Copy link
Contributor

@jnyrup jnyrup commented Jun 8, 2023

This PR has three parts each in separate commits:

1: combine initialization of fields with their declaration, this helps avoiding using a field before it has been initialized
2: Some small optimizations on dictionaries.
3: using target-typed new constructors some more places

private readonly ConcurrentDictionary<string, string> _parentIds = new();
private readonly ConcurrentDictionary<string, List<string>> _childIds = new();
private readonly ConcurrentDictionary<string, List<TaskCompletionSource<Frame>>> _waitRequests = new();
private readonly AsyncDictionaryHelper<string, Frame> _asyncFrames;

public FrameTree()
{
_frames = new();
_asyncFrames = new AsyncDictionaryHelper<string, Frame>(_frames, "Frame {0} not found");
Copy link
Member

Choose a reason for hiding this comment

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

I'd love C# to allow us to move this as well.

Copy link
Member

@kblok kblok left a comment

Choose a reason for hiding this comment

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

Looks good! Thank you!
Let me know if you want to implement that nitpick

lib/PuppeteerSharp/Helpers/DictionaryExtensions.cs Outdated Show resolved Hide resolved
lib/PuppeteerSharp/Target.cs Show resolved Hide resolved
@kblok kblok changed the title Initialization Improve variable initialization Jun 8, 2023
@jnyrup
Copy link
Contributor Author

jnyrup commented Jun 9, 2023

All actionable comments should be resolved now.

@kblok kblok merged commit 6d6cfb1 into hardkoded:master Jun 9, 2023
@jnyrup jnyrup deleted the initialization branch June 13, 2023 06:06
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