Lucene.Net.Core.Util.Fst.PairOutputs: If the generic type is a reference type, we use Collections.Equals() and Collections.GetHashCode() so its values are compared if it happens to be a collection
Project: http://git-wip-us.apache.org/repos/asf/lucenenet/repo Commit: http://git-wip-us.apache.org/repos/asf/lucenenet/commit/d48493df Tree: http://git-wip-us.apache.org/repos/asf/lucenenet/tree/d48493df Diff: http://git-wip-us.apache.org/repos/asf/lucenenet/diff/d48493df Branch: refs/heads/api-work Commit: d48493df8ffd9afded38a4ee4660289270cc2679 Parents: 5c512dd Author: Shad Storhaug <[email protected]> Authored: Thu Mar 30 08:36:05 2017 +0700 Committer: Shad Storhaug <[email protected]> Committed: Thu Mar 30 09:12:32 2017 +0700 ---------------------------------------------------------------------- src/Lucene.Net.Core/Util/Fst/PairOutputs.cs | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/lucenenet/blob/d48493df/src/Lucene.Net.Core/Util/Fst/PairOutputs.cs ---------------------------------------------------------------------- diff --git a/src/Lucene.Net.Core/Util/Fst/PairOutputs.cs b/src/Lucene.Net.Core/Util/Fst/PairOutputs.cs index 7ba14ac..c308940 100644 --- a/src/Lucene.Net.Core/Util/Fst/PairOutputs.cs +++ b/src/Lucene.Net.Core/Util/Fst/PairOutputs.cs @@ -40,11 +40,21 @@ namespace Lucene.Net.Util.Fst public A Output1 { get; private set; } public B Output2 { get; private set; } + // LUCENENET specific - track whether we have value or reference types + // for optimization of Equals and GetHashCode() + private readonly bool output1IsValueType; + private readonly bool output2IsValueType; + // use newPair internal Pair(A output1, B output2) { this.Output1 = output1; this.Output2 = output2; + + // LUCENENET specific - track whether we have value or reference types + // for optimization of Equals and GetHashCode() + this.output1IsValueType = typeof(A).IsValueType; + this.output2IsValueType = typeof(B).IsValueType; } public override bool Equals(object other) @@ -56,7 +66,11 @@ namespace Lucene.Net.Util.Fst else if (other is Pair) { var pair = (Pair)other; - return Output1.Equals(pair.Output1) && Output2.Equals(pair.Output2); + + // LUCENENET specific - if we have reference types, they might be collections that need to be compared + // as sets of values. + return output1IsValueType ? Output1.Equals(pair.Output1) : Collections.Equals(Output1, pair.Output1) + && output2IsValueType ? Output2.Equals(pair.Output2) : Collections.Equals(Output2, pair.Output2); } else { @@ -66,7 +80,10 @@ namespace Lucene.Net.Util.Fst public override int GetHashCode() { - return Output1.GetHashCode() + Output2.GetHashCode(); + // LUCENENET specific - if we have reference types, they might be collections that need to be compared + // as sets of values. + return (output1IsValueType ? Output1.GetHashCode() : Collections.GetHashCode(Output1)) + + (output2IsValueType ? Output2.GetHashCode() : Collections.GetHashCode(Output2)); } }
