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

Tidy up code and eliminate some allocations #378

Merged
merged 12 commits into from
Jan 27, 2024

Conversation

iamcarbon
Copy link
Collaborator

  • Eliminate a possible virtual call in ByteTrieNode
  • Updates ShouldAcceptRiffIdentifier to accept utf-8 bytes (eliminating a string allocation)
  • Eliminates an allocation in GifReader
  • Updates a few classes to use primary constructors
  • Replaces some || statements with pattern matching
  • Avoids an extra dictionary lookup
  • Organizes using statements
  • Fixes a few files with mixed line endings

@iamcarbon
Copy link
Collaborator Author

@drewnoakes Ready for review / comments.

@iamcarbon iamcarbon changed the title Improve code quality Tidy up code, and eliminate some allocations Jan 27, 2024
@iamcarbon iamcarbon changed the title Tidy up code, and eliminate some allocations Tidy up code and eliminate some allocations Jan 27, 2024
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.

Nice! Good to go as is. Left a few thoughts if you want them. Can merge when you're happy.

@@ -482,34 +482,21 @@ public OlympusMakernoteDescriptor(OlympusMakernoteDirectory directory)
if (Directory.GetObject(OlympusMakernoteDirectory.TagWbMode) is not short[] values)
return null;

switch ($"{values[0]} {values[1]}".Trim())
return $"{values[0]} {values[1]}".Trim() switch
Copy link
Owner

Choose a reason for hiding this comment

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

This could be a switch on a tuple, to avoid the string allocation and hopefully enable a jump table.

Eg

Suggested change
return $"{values[0]} {values[1]}".Trim() switch
return (values[0], values[1]) switch

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Added a dependency to ValueTuple, and updated.

MetadataExtractor/Formats/Riff/RiffReader.cs Show resolved Hide resolved
MetadataExtractor/KeyValuePair.cs Outdated Show resolved Hide resolved
@iamcarbon
Copy link
Collaborator Author

iamcarbon commented Jan 27, 2024

@drewnoakes Ready to merge if everything looks good to you. I'll hit the rest in another PR.

@drewnoakes drewnoakes merged commit 93e1bd4 into drewnoakes:master Jan 27, 2024
4 checks passed
@drewnoakes
Copy link
Owner

Thanks again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants