Skip to content

Teach LambdaEqualityHelper to deal with null equality contribution#541

Merged
nulltoken merged 1 commit into
libgit2:vNextfrom
ethomson:equalityhelper
Oct 22, 2013
Merged

Teach LambdaEqualityHelper to deal with null equality contribution#541
nulltoken merged 1 commit into
libgit2:vNextfrom
ethomson:equalityhelper

Conversation

@ethomson

Copy link
Copy Markdown
Member

No description provided.

@dahlbyk

dahlbyk commented Oct 22, 2013

Copy link
Copy Markdown
Member

@nulltoken

Copy link
Copy Markdown
Member

@ethomson I'd indeed prefer not to make LambdaEqualityHelper public. I kind of like @dahlbyk's counter proposal.

FWIW, I found a clear case in LibGit2Sharp which demonstrates this issue.

[Fact]
public void CanRetrieveHashCodeFromAnUnbornBranch()
{
    string path = InitNewRepository();
    using (var repo = new Repository(path))
    {
        Assert.DoesNotThrow(() => repo.Head.GetHashCode());
    }
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Rather than using 0 (which would level down the previous computation steps to 1), how about using a bit larger number (eg. The Java 31 or whatever...)

@ethomson

Copy link
Copy Markdown
Member Author

I don't think I'm following entirely; should XORing with zero versus one change the distribution significantly?

Note that Joshua Bloch's hashCode is the reference implantation that I think you're referring to, and uses 0 in this case for null elements.

@nulltoken

Copy link
Copy Markdown
Member

Duh. Ignore me.

I don't know why, but I forgot that ^ doesn't refer to a "power-of" function in C#. Sorry for the noise. 😊

@ethomson

Copy link
Copy Markdown
Member Author

I brought in @dahlbyk 's tests. This is one of the few times I wish for java's package protection...!

@dahlbyk

dahlbyk commented Oct 22, 2013

Copy link
Copy Markdown
Member

This is one of the few times I wish for java's package protection...!

We could achieve a similar effect with InternalsVisibleTo, though that feels like cheating.

@ethomson

Copy link
Copy Markdown
Member Author

Squashed, rebased, etc.

@nulltoken
nulltoken merged commit 7af5c60 into libgit2:vNext Oct 22, 2013
@nulltoken

Copy link
Copy Markdown
Member

Very nice catch!

❤️ to both of you.

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.

3 participants