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

Introduce ScopedBuffer #415

Merged
merged 8 commits into from
Feb 23, 2024
Merged

Introduce ScopedBuffer #415

merged 8 commits into from
Feb 23, 2024

Conversation

iamcarbon
Copy link
Collaborator

This PR extracts the ScopedBuffer work from #406

Local regression testing shows no diffs.

@drewnoakes Ready for review.

Copy link
Owner

@drewnoakes drewnoakes left a comment

Choose a reason for hiding this comment

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

Looks great. I like this pattern a lot. Much nicer than repeating ourselves all over the place.

Left a few comments for you to consider. Have approved, so merge it whenever you're happy with it, or let me know if you want me to take another look later on.

#if NET8_0 || NETSTANDARD2_1
#if NET8_0_OR_GREATER || NETSTANDARD2_1
Copy link
Owner

Choose a reason for hiding this comment

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

Thanks for fixing this. I searched and couldn't find any other instances.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yep, also searched -- and only one I found!

Comment on lines 126 to 124
var keyRefs = ArrayPool<byte>.Shared.Rent(count);
Span<byte> keyRefs = stackalloc byte[count]; // <= 255
Copy link
Owner

Choose a reason for hiding this comment

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

Could we convert the comment into a Debug.Assert(count <= 255) instead? It provides a little more safety and is clearer as far as documenting intent.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I updated the comment to be clearer (count is an unsigned byte, with a safe range) -- no need for an assert. The comment saves a second when auditing the stackalloc call sites.

MetadataExtractor/IO/BufferReader.Indexed.cs Outdated Show resolved Hide resolved
@@ -193,17 +195,11 @@ namespace MetadataExtractor.IO;
}
else
Copy link
Owner

Choose a reason for hiding this comment

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

Do we need the else block any more? Looks like the size check could be moved into a ternary conditional and the two blocks collapsed into one, as you've done elsewhere in the PR.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

unified the logic across all the readers. much tidier.

MetadataExtractor/IO/BufferReader.Sequential.cs Outdated Show resolved Hide resolved
MetadataExtractor/IO/ScopedBuffer.cs Outdated Show resolved Hide resolved
@iamcarbon
Copy link
Collaborator Author

Addressed all feedback, and double checked against regressions. Merged!

@iamcarbon iamcarbon merged commit ec5fe3c into drewnoakes:main Feb 23, 2024
2 checks passed
@drewnoakes
Copy link
Owner

Looks great, thanks.

FYI I will be less online over the next week but will do my best to review any PRs.

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