-
-
Notifications
You must be signed in to change notification settings - Fork 416
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
perf: use index access to Dictionary #1621
Conversation
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.
Wondering if we should not change the interface instead? Als a bit surprised this doesn't cause a warning?
src/Magick.NET/Statistics/Moments.cs
Outdated
@@ -37,10 +37,7 @@ public IChannelMoments Composite() | |||
/// <param name="channel">The channel to get the moments for.</param> | |||
/// <returns>The moments for the specified channel.</returns> | |||
public IChannelMoments GetChannel(PixelChannel channel) |
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.
Should we not change the interface here instead and do IChannelMoments?
public class TheGetChannelMethod | ||
{ | ||
[Fact] | ||
public void ShouldThrowExceptionWhenChannelDoesNotExist() |
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.
This name is no longer correct?
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.
Yup; renamed.
public class TheGetChannelMethod | ||
{ | ||
[Fact] | ||
public void ShouldThrowExceptionWhenChannelDoesNotExist() |
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.
Same here :)
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.
Renamed.
using ImageMagick; | ||
using Xunit; | ||
|
||
namespace Magick.NET.Tests; | ||
|
||
public partial class PerceptualHashTests | ||
{ | ||
public class TestPerceptualHash : IPerceptualHash |
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.
I will move this to a separate file after merging this PR. Not yet sure where I want to put this. And maybe we could use NSubstitute
instead?
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.
I'm used to anonymous object that can implements an Interface in PHP or Kotlin 😜
I don't know NSubstitute
(this one?), but I could use it instead of this Test class.
{ | ||
public IChannelPerceptualHash GetChannel(PixelChannel channel) | ||
{ | ||
return null; |
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.
Please use => null
instead.
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.
Fixed.
using var image = new MagickImage(Files.ImageMagickJPG); | ||
var phash = image.PerceptualHash(); | ||
|
||
Assert.Throws<NotSupportedException>(() => phash.SumSquaredDistance(new TestPerceptualHash())); |
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.
You can also check the message of the exception like we do in other places.
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.
Added.
I can't rerun the pipeline; it seems stuck like "last time", not because of code, but for some other reasons |
You will probably need to rebase your PR? |
Description
👋
Theses method doesn't use the result of
TryGetValue
and expect a non-null result:Magick.NET/src/Magick.NET/Statistics/Moments.cs
Lines 39 to 43 in d58472f
Magick.NET/src/Magick.NET/Statistics/PerceptualHash.cs
Lines 66 to 70 in d58472f
This one can - explicitly - return a null value:
Magick.NET/src/Magick.NET/Statistics/Statistics.cs
Lines 35 to 39 in d58472f
This PR:
TryGetValue
for the first too method and use index accessIf otherwise you prefer to not change the actual behavior (as it might be a breaking change, or just because the nullable returns is the wanted behavior), I will update the PR:
Regards.