From 677e8eb4e77678113415742c7cc15094b13b49ef Mon Sep 17 00:00:00 2001 From: Shad Storhaug Date: Sun, 24 Oct 2021 04:42:45 +0700 Subject: [PATCH] SWEEP: Lucene.Net: Use NumericUtils.SingleToSortableInt32() to compare floating point numbers (except in cases where we are testing for whole numbers). --- src/Lucene.Net/Search/BooleanQuery.cs | 4 +++- src/Lucene.Net/Search/DisjunctionMaxQuery.cs | 5 +++-- src/Lucene.Net/Search/FieldCache.cs | 3 ++- src/Lucene.Net/Search/HitQueue.cs | 7 ++++--- src/Lucene.Net/Search/IndexSearcher.cs | 4 +++- src/Lucene.Net/Search/MatchAllDocsQuery.cs | 4 +++- src/Lucene.Net/Search/MultiPhraseQuery.cs | 8 +++++--- src/Lucene.Net/Search/PhraseQuery.cs | 4 +++- src/Lucene.Net/Search/QueryRescorer.cs | 8 +++++--- src/Lucene.Net/Search/ScoringRewrite.cs | 6 ++++-- .../Search/Spans/FieldMaskingSpanQuery.cs | 6 +++++- src/Lucene.Net/Search/Spans/SpanFirstQuery.cs | 6 +++++- .../Search/Spans/SpanNearPayloadCheckQuery.cs | 8 +++++--- src/Lucene.Net/Search/Spans/SpanNearQuery.cs | 4 +++- src/Lucene.Net/Search/Spans/SpanOrQuery.cs | 4 +++- .../Search/Spans/SpanPayloadCheckQuery.cs | 8 +++++--- .../Search/Spans/SpanPositionRangeQuery.cs | 6 +++++- src/Lucene.Net/Search/TermQuery.cs | 5 ++++- src/Lucene.Net/Search/TopDocs.cs | 6 ++++-- src/Lucene.Net/Search/TopFieldCollector.cs | 15 ++++++++++----- src/Lucene.Net/Search/TopTermsRewrite.cs | 15 ++++++++++----- src/Lucene.Net/Util/Mutable/MutableValueDouble.cs | 4 +++- src/Lucene.Net/Util/Mutable/MutableValueFloat.cs | 6 ++++-- src/Lucene.Net/Util/Packed/PackedInts.cs | 3 ++- 24 files changed, 103 insertions(+), 46 deletions(-) diff --git a/src/Lucene.Net/Search/BooleanQuery.cs b/src/Lucene.Net/Search/BooleanQuery.cs index bd1c529026..13c412edec 100644 --- a/src/Lucene.Net/Search/BooleanQuery.cs +++ b/src/Lucene.Net/Search/BooleanQuery.cs @@ -1,5 +1,6 @@ using J2N; using J2N.Collections.Generic.Extensions; +using Lucene.Net.Util; using System; using System.Collections; using System.Collections.Generic; @@ -681,7 +682,8 @@ public override bool Equals(object o) return false; } BooleanQuery other = (BooleanQuery)o; - return this.Boost == other.Boost + // LUCENENET specific - compare bits rather than using equality operators to prevent these comparisons from failing in x86 in .NET Framework with optimizations enabled + return NumericUtils.SingleToSortableInt32(this.Boost) == NumericUtils.SingleToSortableInt32(other.Boost) && this.clauses.Equals(other.clauses) && this.MinimumNumberShouldMatch == other.MinimumNumberShouldMatch && this.disableCoord == other.disableCoord; diff --git a/src/Lucene.Net/Search/DisjunctionMaxQuery.cs b/src/Lucene.Net/Search/DisjunctionMaxQuery.cs index 35c8a4aaa5..1d3358df78 100644 --- a/src/Lucene.Net/Search/DisjunctionMaxQuery.cs +++ b/src/Lucene.Net/Search/DisjunctionMaxQuery.cs @@ -357,8 +357,9 @@ public override bool Equals(object o) return false; } DisjunctionMaxQuery other = (DisjunctionMaxQuery)o; - return this.Boost == other.Boost - && this.tieBreakerMultiplier == other.tieBreakerMultiplier + // LUCENENET specific - compare bits rather than using equality operators to prevent these comparisons from failing in x86 in .NET Framework with optimizations enabled + return NumericUtils.SingleToSortableInt32(this.Boost) == NumericUtils.SingleToSortableInt32(other.Boost) + && NumericUtils.SingleToSortableInt32(this.tieBreakerMultiplier) == NumericUtils.SingleToSortableInt32(other.tieBreakerMultiplier) && this.disjuncts.Equals(other.disjuncts); } diff --git a/src/Lucene.Net/Search/FieldCache.cs b/src/Lucene.Net/Search/FieldCache.cs index daf1447c67..63812bc540 100644 --- a/src/Lucene.Net/Search/FieldCache.cs +++ b/src/Lucene.Net/Search/FieldCache.cs @@ -1127,7 +1127,8 @@ public override bool Equals(object obj) { if (obj is AcceptableOverheadRatio other) { - return Value.Equals(other.Value); + // LUCENENET specific - compare bits rather than using equality operators to prevent these comparisons from failing in x86 in .NET Framework with optimizations enabled + return NumericUtils.SingleToSortableInt32(Value) == NumericUtils.SingleToSortableInt32(other.Value); } return false; } diff --git a/src/Lucene.Net/Search/HitQueue.cs b/src/Lucene.Net/Search/HitQueue.cs index 44d481a562..0bc01ebc71 100644 --- a/src/Lucene.Net/Search/HitQueue.cs +++ b/src/Lucene.Net/Search/HitQueue.cs @@ -1,4 +1,4 @@ -namespace Lucene.Net.Search +namespace Lucene.Net.Search { /* * Licensed to the Apache Software Foundation (ASF) under one or more @@ -76,13 +76,14 @@ protected override ScoreDoc GetSentinelObject() protected internal override sealed bool LessThan(ScoreDoc hitA, ScoreDoc hitB) { - if (hitA.Score == hitB.Score) + // LUCENENET specific - compare bits rather than using equality operators to prevent these comparisons from failing in x86 in .NET Framework with optimizations enabled + if (NumericUtils.SingleToSortableInt32(hitA.Score) == NumericUtils.SingleToSortableInt32(hitB.Score)) { return hitA.Doc > hitB.Doc; } else { - return hitA.Score < hitB.Score; + return NumericUtils.SingleToSortableInt32(hitA.Score) < NumericUtils.SingleToSortableInt32(hitB.Score); } } } diff --git a/src/Lucene.Net/Search/IndexSearcher.cs b/src/Lucene.Net/Search/IndexSearcher.cs index f76d9919e4..712de33323 100644 --- a/src/Lucene.Net/Search/IndexSearcher.cs +++ b/src/Lucene.Net/Search/IndexSearcher.cs @@ -1,6 +1,7 @@ using Lucene.Net.Diagnostics; using Lucene.Net.Support; using Lucene.Net.Support.Threading; +using Lucene.Net.Util; using System; using System.Collections; using System.Collections.Generic; @@ -818,7 +819,8 @@ public TopFieldDocs Call() } // Carry over maxScore from sub: - if (doMaxScore && docs.MaxScore > hq.maxScore) + // LUCENENET specific - compare bits rather than using equality operators to prevent these comparisons from failing in x86 in .NET Framework with optimizations enabled + if (doMaxScore && NumericUtils.SingleToSortableInt32(docs.MaxScore) > NumericUtils.SingleToSortableInt32(hq.maxScore)) { hq.maxScore = docs.MaxScore; } diff --git a/src/Lucene.Net/Search/MatchAllDocsQuery.cs b/src/Lucene.Net/Search/MatchAllDocsQuery.cs index f76beed91f..eda5d3e478 100644 --- a/src/Lucene.Net/Search/MatchAllDocsQuery.cs +++ b/src/Lucene.Net/Search/MatchAllDocsQuery.cs @@ -1,3 +1,4 @@ +using Lucene.Net.Util; using System.Collections.Generic; using System.Text; @@ -155,7 +156,8 @@ public override bool Equals(object o) return false; } MatchAllDocsQuery other = (MatchAllDocsQuery)o; - return this.Boost == other.Boost; + // LUCENENET specific - compare bits rather than using equality operators to prevent these comparisons from failing in x86 in .NET Framework with optimizations enabled + return NumericUtils.SingleToSortableInt32(this.Boost) == NumericUtils.SingleToSortableInt32(other.Boost); } public override int GetHashCode() diff --git a/src/Lucene.Net/Search/MultiPhraseQuery.cs b/src/Lucene.Net/Search/MultiPhraseQuery.cs index 69f34d348b..06e6048b2f 100644 --- a/src/Lucene.Net/Search/MultiPhraseQuery.cs +++ b/src/Lucene.Net/Search/MultiPhraseQuery.cs @@ -26,6 +26,7 @@ namespace Lucene.Net.Search */ using J2N.Collections.Generic.Extensions; + using Lucene.Net.Util; using System.Collections; using ArrayUtil = Lucene.Net.Util.ArrayUtil; using AtomicReader = Lucene.Net.Index.AtomicReader; @@ -444,9 +445,10 @@ public override bool Equals(object o) return false; } MultiPhraseQuery other = (MultiPhraseQuery)o; - return this.Boost == other.Boost - && this.slop == other.slop - && TermArraysEquals(this.termArrays, other.termArrays) + // LUCENENET specific - compare bits rather than using equality operators to prevent these comparisons from failing in x86 in .NET Framework with optimizations enabled + return NumericUtils.SingleToSortableInt32(this.Boost) == NumericUtils.SingleToSortableInt32(other.Boost) + && this.slop == other.slop + && TermArraysEquals(this.termArrays, other.termArrays) && this.positions.Equals(other.positions); } diff --git a/src/Lucene.Net/Search/PhraseQuery.cs b/src/Lucene.Net/Search/PhraseQuery.cs index 4160b079dc..b598099d74 100644 --- a/src/Lucene.Net/Search/PhraseQuery.cs +++ b/src/Lucene.Net/Search/PhraseQuery.cs @@ -2,6 +2,7 @@ using Lucene.Net.Diagnostics; using Lucene.Net.Index; using Lucene.Net.Support; +using Lucene.Net.Util; using System; using System.Collections; using System.Collections.Generic; @@ -504,7 +505,8 @@ public override bool Equals(object o) return false; } PhraseQuery other = (PhraseQuery)o; - return (this.Boost == other.Boost) + // LUCENENET specific - compare bits rather than using equality operators to prevent these comparisons from failing in x86 in .NET Framework with optimizations enabled + return (NumericUtils.SingleToSortableInt32(this.Boost) == NumericUtils.SingleToSortableInt32(other.Boost)) && (this.slop == other.slop) && this.terms.Equals(other.terms) && this.positions.Equals(other.positions); diff --git a/src/Lucene.Net/Search/QueryRescorer.cs b/src/Lucene.Net/Search/QueryRescorer.cs index 9dd70d0054..df53424242 100644 --- a/src/Lucene.Net/Search/QueryRescorer.cs +++ b/src/Lucene.Net/Search/QueryRescorer.cs @@ -1,4 +1,5 @@ -using Lucene.Net.Diagnostics; +using Lucene.Net.Diagnostics; +using Lucene.Net.Util; using System; using System.Collections.Generic; @@ -114,11 +115,12 @@ public override TopDocs Rescore(IndexSearcher searcher, TopDocs firstPassTopDocs Array.Sort(hits, Comparer.Create((a, b) => { // Sort by score descending, then docID ascending: - if (a.Score > b.Score) + // LUCENENET specific - compare bits rather than using equality operators to prevent these comparisons from failing in x86 in .NET Framework with optimizations enabled + if (NumericUtils.SingleToSortableInt32(a.Score) > NumericUtils.SingleToSortableInt32(b.Score)) { return -1; } - else if (a.Score < b.Score) + else if (NumericUtils.SingleToSortableInt32(a.Score) < NumericUtils.SingleToSortableInt32(b.Score)) { return 1; } diff --git a/src/Lucene.Net/Search/ScoringRewrite.cs b/src/Lucene.Net/Search/ScoringRewrite.cs index 67de649a49..1ed03ff9ce 100644 --- a/src/Lucene.Net/Search/ScoringRewrite.cs +++ b/src/Lucene.Net/Search/ScoringRewrite.cs @@ -1,4 +1,5 @@ -using Lucene.Net.Diagnostics; +using Lucene.Net.Diagnostics; +using Lucene.Net.Util; using System; namespace Lucene.Net.Search @@ -174,7 +175,8 @@ public override bool Collect(BytesRef bytes) // duplicate term: update docFreq int pos = (-e) - 1; array.termState[pos].Register(state, m_readerContext.Ord, termsEnum.DocFreq, termsEnum.TotalTermFreq); - if (Debugging.AssertsEnabled) Debugging.Assert(array.boost[pos] == boostAtt.Boost, "boost should be equal in all segment TermsEnums"); + // LUCENENET specific - compare bits rather than using equality operators to prevent these comparisons from failing in x86 in .NET Framework with optimizations enabled + if (Debugging.AssertsEnabled) Debugging.Assert(NumericUtils.SingleToSortableInt32(array.boost[pos]) == NumericUtils.SingleToSortableInt32(boostAtt.Boost), "boost should be equal in all segment TermsEnums"); } else { diff --git a/src/Lucene.Net/Search/Spans/FieldMaskingSpanQuery.cs b/src/Lucene.Net/Search/Spans/FieldMaskingSpanQuery.cs index 8a16895c3d..5a1782a394 100644 --- a/src/Lucene.Net/Search/Spans/FieldMaskingSpanQuery.cs +++ b/src/Lucene.Net/Search/Spans/FieldMaskingSpanQuery.cs @@ -1,3 +1,4 @@ +using Lucene.Net.Util; using System; using System.Collections.Generic; using System.Text; @@ -144,7 +145,10 @@ public override bool Equals(object o) return false; } FieldMaskingSpanQuery other = (FieldMaskingSpanQuery)o; - return (this.Field.Equals(other.Field, StringComparison.Ordinal) && (this.Boost == other.Boost) && this.MaskedQuery.Equals(other.MaskedQuery)); + // LUCENENET specific - compare bits rather than using equality operators to prevent these comparisons from failing in x86 in .NET Framework with optimizations enabled + return (this.Field.Equals(other.Field, StringComparison.Ordinal) + && (NumericUtils.SingleToSortableInt32(this.Boost) == NumericUtils.SingleToSortableInt32(other.Boost)) + && this.MaskedQuery.Equals(other.MaskedQuery)); } public override int GetHashCode() diff --git a/src/Lucene.Net/Search/Spans/SpanFirstQuery.cs b/src/Lucene.Net/Search/Spans/SpanFirstQuery.cs index 57d69643d9..fd393f545f 100644 --- a/src/Lucene.Net/Search/Spans/SpanFirstQuery.cs +++ b/src/Lucene.Net/Search/Spans/SpanFirstQuery.cs @@ -1,5 +1,6 @@ using J2N.Numerics; using Lucene.Net.Diagnostics; +using Lucene.Net.Util; using System.Text; namespace Lucene.Net.Search.Spans @@ -88,7 +89,10 @@ public override bool Equals(object o) } SpanFirstQuery other = (SpanFirstQuery)o; - return this.m_end == other.m_end && this.m_match.Equals(other.m_match) && this.Boost == other.Boost; + // LUCENENET specific - compare bits rather than using equality operators to prevent these comparisons from failing in x86 in .NET Framework with optimizations enabled + return this.m_end == other.m_end + && this.m_match.Equals(other.m_match) + && NumericUtils.SingleToSortableInt32(this.Boost) == NumericUtils.SingleToSortableInt32(other.Boost); } public override int GetHashCode() diff --git a/src/Lucene.Net/Search/Spans/SpanNearPayloadCheckQuery.cs b/src/Lucene.Net/Search/Spans/SpanNearPayloadCheckQuery.cs index 73a8f49dbb..0839c6c6e3 100644 --- a/src/Lucene.Net/Search/Spans/SpanNearPayloadCheckQuery.cs +++ b/src/Lucene.Net/Search/Spans/SpanNearPayloadCheckQuery.cs @@ -1,5 +1,6 @@ using J2N.Numerics; using Lucene.Net.Support; +using Lucene.Net.Util; using System.Collections; using System.Collections.Generic; using System.Text; @@ -130,9 +131,10 @@ public override bool Equals(object o) } // LUCENENET NOTE: Need to use the structural equality comparer to compare equality of all contained values - return payloadEqualityComparer.Equals(this.m_payloadToMatch, other.m_payloadToMatch) - && this.m_match.Equals(other.m_match) - && this.Boost == other.Boost; + return payloadEqualityComparer.Equals(this.m_payloadToMatch, other.m_payloadToMatch) + && this.m_match.Equals(other.m_match) + // LUCENENET specific - compare bits rather than using equality operators to prevent these comparisons from failing in x86 in .NET Framework with optimizations enabled + && NumericUtils.SingleToSortableInt32(this.Boost) == NumericUtils.SingleToSortableInt32(other.Boost); } public override int GetHashCode() diff --git a/src/Lucene.Net/Search/Spans/SpanNearQuery.cs b/src/Lucene.Net/Search/Spans/SpanNearQuery.cs index 4d419f8704..21a058e1b9 100644 --- a/src/Lucene.Net/Search/Spans/SpanNearQuery.cs +++ b/src/Lucene.Net/Search/Spans/SpanNearQuery.cs @@ -1,5 +1,6 @@ using J2N.Collections.Generic.Extensions; using J2N.Numerics; +using Lucene.Net.Util; using System; using System.Collections.Generic; using System.Text; @@ -209,7 +210,8 @@ public override bool Equals(object o) return false; } - return Boost == spanNearQuery.Boost; + // LUCENENET specific - compare bits rather than using equality operators to prevent these comparisons from failing in x86 in .NET Framework with optimizations enabled + return NumericUtils.SingleToSortableInt32(Boost) == NumericUtils.SingleToSortableInt32(spanNearQuery.Boost); } public override int GetHashCode() diff --git a/src/Lucene.Net/Search/Spans/SpanOrQuery.cs b/src/Lucene.Net/Search/Spans/SpanOrQuery.cs index 484e4cf843..2d9e2973e8 100644 --- a/src/Lucene.Net/Search/Spans/SpanOrQuery.cs +++ b/src/Lucene.Net/Search/Spans/SpanOrQuery.cs @@ -1,5 +1,6 @@ using J2N.Collections.Generic.Extensions; using J2N.Numerics; +using Lucene.Net.Util; using System; using System.Collections.Generic; using System.Text; @@ -163,7 +164,8 @@ public override bool Equals(object o) return false; } - return Boost == that.Boost; + // LUCENENET specific - compare bits rather than using equality operators to prevent these comparisons from failing in x86 in .NET Framework with optimizations enabled + return NumericUtils.SingleToSortableInt32(Boost) == NumericUtils.SingleToSortableInt32(that.Boost); } public override int GetHashCode() diff --git a/src/Lucene.Net/Search/Spans/SpanPayloadCheckQuery.cs b/src/Lucene.Net/Search/Spans/SpanPayloadCheckQuery.cs index 9fb0dc20f9..7bd4b45321 100644 --- a/src/Lucene.Net/Search/Spans/SpanPayloadCheckQuery.cs +++ b/src/Lucene.Net/Search/Spans/SpanPayloadCheckQuery.cs @@ -4,6 +4,7 @@ using System.Text; using System.Collections; using J2N.Numerics; +using Lucene.Net.Util; namespace Lucene.Net.Search.Spans { @@ -134,9 +135,10 @@ public override bool Equals(object o) SpanPayloadCheckQuery other = (SpanPayloadCheckQuery)o; // LUCENENET NOTE: Need to use the structural equality comparer to compare equality of all contained values - return payloadEqualityComparer.Equals(this.m_payloadToMatch, other.m_payloadToMatch) - && this.m_match.Equals(other.m_match) - && this.Boost == other.Boost; + return payloadEqualityComparer.Equals(this.m_payloadToMatch, other.m_payloadToMatch) + && this.m_match.Equals(other.m_match) + // LUCENENET specific - compare bits rather than using equality operators to prevent these comparisons from failing in x86 in .NET Framework with optimizations enabled + && NumericUtils.SingleToSortableInt32(this.Boost) == NumericUtils.SingleToSortableInt32(other.Boost); } public override int GetHashCode() diff --git a/src/Lucene.Net/Search/Spans/SpanPositionRangeQuery.cs b/src/Lucene.Net/Search/Spans/SpanPositionRangeQuery.cs index b37b948397..1ae24c26dd 100644 --- a/src/Lucene.Net/Search/Spans/SpanPositionRangeQuery.cs +++ b/src/Lucene.Net/Search/Spans/SpanPositionRangeQuery.cs @@ -1,5 +1,6 @@ using J2N.Numerics; using Lucene.Net.Diagnostics; +using Lucene.Net.Util; using System.Text; namespace Lucene.Net.Search.Spans @@ -93,7 +94,10 @@ public override bool Equals(object o) } SpanPositionRangeQuery other = (SpanPositionRangeQuery)o; - return this.m_end == other.m_end && this.m_start == other.m_start && this.m_match.Equals(other.m_match) && this.Boost == other.Boost; + // LUCENENET specific - compare bits rather than using equality operators to prevent these comparisons from failing in x86 in .NET Framework with optimizations enabled + return this.m_end == other.m_end + && this.m_start == other.m_start + && this.m_match.Equals(other.m_match) && NumericUtils.SingleToSortableInt32(this.Boost) == NumericUtils.SingleToSortableInt32(other.Boost); } public override int GetHashCode() diff --git a/src/Lucene.Net/Search/TermQuery.cs b/src/Lucene.Net/Search/TermQuery.cs index e9bb64607e..f3469d4e95 100644 --- a/src/Lucene.Net/Search/TermQuery.cs +++ b/src/Lucene.Net/Search/TermQuery.cs @@ -1,4 +1,5 @@ using Lucene.Net.Diagnostics; +using Lucene.Net.Util; using System; using System.Collections.Generic; using System.Text; @@ -233,7 +234,9 @@ public override bool Equals(object o) return false; } TermQuery other = (TermQuery)o; - return (this.Boost == other.Boost) && this.term.Equals(other.term); + // LUCENENET specific - compare bits rather than using equality operators to prevent these comparisons from failing in x86 in .NET Framework with optimizations enabled + return (NumericUtils.SingleToSortableInt32(this.Boost) == NumericUtils.SingleToSortableInt32(other.Boost)) + && this.term.Equals(other.term); } /// diff --git a/src/Lucene.Net/Search/TopDocs.cs b/src/Lucene.Net/Search/TopDocs.cs index c142bad448..38a5e76265 100644 --- a/src/Lucene.Net/Search/TopDocs.cs +++ b/src/Lucene.Net/Search/TopDocs.cs @@ -1,5 +1,6 @@ using Lucene.Net.Diagnostics; using Lucene.Net.Support; +using Lucene.Net.Util; using System; using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; @@ -111,11 +112,12 @@ protected internal override bool LessThan(ShardRef first, ShardRef second) float firstScore = shardHits[first.ShardIndex][first.HitIndex].Score; float secondScore = shardHits[second.ShardIndex][second.HitIndex].Score; - if (firstScore < secondScore) + // LUCENENET specific - compare bits rather than using equality operators to prevent these comparisons from failing in x86 in .NET Framework with optimizations enabled + if (NumericUtils.SingleToSortableInt32(firstScore) < NumericUtils.SingleToSortableInt32(secondScore)) { return false; } - else if (firstScore > secondScore) + else if (NumericUtils.SingleToSortableInt32(firstScore) > NumericUtils.SingleToSortableInt32(secondScore)) { return true; } diff --git a/src/Lucene.Net/Search/TopFieldCollector.cs b/src/Lucene.Net/Search/TopFieldCollector.cs index df83744f9a..8e94e0e642 100644 --- a/src/Lucene.Net/Search/TopFieldCollector.cs +++ b/src/Lucene.Net/Search/TopFieldCollector.cs @@ -299,7 +299,8 @@ internal void UpdateBottom(int doc, float score) public override void Collect(int doc) { float score = scorer.GetScore(); - if (score > maxScore) + // LUCENENET specific - compare bits rather than using equality operators to prevent these comparisons from failing in x86 in .NET Framework with optimizations enabled + if (NumericUtils.SingleToSortableInt32(score) > NumericUtils.SingleToSortableInt32(maxScore)) { maxScore = score; } @@ -355,7 +356,8 @@ public OutOfOrderOneComparerScoringMaxScoreCollector(FieldValueHitQueue q public override void Collect(int doc) { float score = scorer.GetScore(); - if (score > maxScore) + // LUCENENET specific - compare bits rather than using equality operators to prevent these comparisons from failing in x86 in .NET Framework with optimizations enabled + if (NumericUtils.SingleToSortableInt32(score) > NumericUtils.SingleToSortableInt32(maxScore)) { maxScore = score; } @@ -600,7 +602,8 @@ internal void UpdateBottom(int doc, float score) public override void Collect(int doc) { float score = scorer.GetScore(); - if (score > maxScore) + // LUCENENET specific - compare bits rather than using equality operators to prevent these comparisons from failing in x86 in .NET Framework with optimizations enabled + if (NumericUtils.SingleToSortableInt32(score) > NumericUtils.SingleToSortableInt32(maxScore)) { maxScore = score; } @@ -685,7 +688,8 @@ public OutOfOrderMultiComparerScoringMaxScoreCollector(FieldValueHitQueue public override void Collect(int doc) { float score = scorer.GetScore(); - if (score > maxScore) + // LUCENENET specific - compare bits rather than using equality operators to prevent these comparisons from failing in x86 in .NET Framework with optimizations enabled + if (NumericUtils.SingleToSortableInt32(score) > NumericUtils.SingleToSortableInt32(maxScore)) { maxScore = score; } @@ -990,7 +994,8 @@ public override void Collect(int doc) if (trackMaxScore) { score = scorer.GetScore(); - if (score > maxScore) + // LUCENENET specific - compare bits rather than using equality operators to prevent these comparisons from failing in x86 in .NET Framework with optimizations enabled + if (NumericUtils.SingleToSortableInt32(score) > NumericUtils.SingleToSortableInt32(maxScore)) { maxScore = score; } diff --git a/src/Lucene.Net/Search/TopTermsRewrite.cs b/src/Lucene.Net/Search/TopTermsRewrite.cs index 08e4a507b4..7d489dbf6d 100644 --- a/src/Lucene.Net/Search/TopTermsRewrite.cs +++ b/src/Lucene.Net/Search/TopTermsRewrite.cs @@ -1,5 +1,6 @@ -using J2N.Collections.Generic.Extensions; +using J2N.Collections.Generic.Extensions; using Lucene.Net.Diagnostics; +using Lucene.Net.Util; using System; using System.Collections.Generic; using JCG = J2N.Collections.Generic; @@ -161,11 +162,13 @@ public override bool Collect(BytesRef bytes) if (stQueue.Count == maxSize) { ScoreTerm t = stQueue.Peek(); - if (boost < t.Boost) + // LUCENENET specific - compare bits rather than using equality operators to prevent these comparisons from failing in x86 in .NET Framework with optimizations enabled + if (NumericUtils.SingleToSortableInt32(boost) < NumericUtils.SingleToSortableInt32(t.Boost)) { return true; } - if (boost == t.Boost && termComp.Compare(bytes, t.Bytes) > 0) + // LUCENENET specific - compare bits rather than using equality operators to prevent these comparisons from failing in x86 in .NET Framework with optimizations enabled + if (NumericUtils.SingleToSortableInt32(boost) == NumericUtils.SingleToSortableInt32(t.Boost) && termComp.Compare(bytes, t.Bytes) > 0) { return true; } @@ -175,7 +178,8 @@ public override bool Collect(BytesRef bytes) if (visitedTerms.TryGetValue(bytes, out ScoreTerm t2)) { // if the term is already in the PQ, only update docFreq of term in PQ - if (Debugging.AssertsEnabled) Debugging.Assert(t2.Boost == boost, "boost should be equal in all segment TermsEnums"); + // LUCENENET specific - compare bits rather than using equality operators to prevent these comparisons from failing in x86 in .NET Framework with optimizations enabled + if (Debugging.AssertsEnabled) Debugging.Assert(NumericUtils.SingleToSortableInt32(t2.Boost) == NumericUtils.SingleToSortableInt32(boost), "boost should be equal in all segment TermsEnums"); t2.TermState.Register(state, m_readerContext.Ord, termsEnum.DocFreq, termsEnum.TotalTermFreq); } else @@ -264,7 +268,8 @@ public ScoreTerm(IComparer termComp, TermContext termState) public int CompareTo(ScoreTerm other) { - if (this.Boost == other.Boost) + // LUCENENET specific - compare bits rather than using equality operators to prevent these comparisons from failing in x86 in .NET Framework with optimizations enabled + if (NumericUtils.SingleToSortableInt32(this.Boost) == NumericUtils.SingleToSortableInt32(other.Boost)) { return TermComp.Compare(other.Bytes, this.Bytes); } diff --git a/src/Lucene.Net/Util/Mutable/MutableValueDouble.cs b/src/Lucene.Net/Util/Mutable/MutableValueDouble.cs index 2490cc8c74..c846f1db6a 100644 --- a/src/Lucene.Net/Util/Mutable/MutableValueDouble.cs +++ b/src/Lucene.Net/Util/Mutable/MutableValueDouble.cs @@ -56,7 +56,9 @@ public override MutableValue Duplicate() public override bool EqualsSameType(object other) { MutableValueDouble b = (MutableValueDouble)other; - return Value == b.Value && Exists == b.Exists; + // LUCENENET specific - compare bits rather than using equality operators to prevent these comparisons from failing in x86 in .NET Framework with optimizations enabled + return NumericUtils.DoubleToSortableInt64(Value) == NumericUtils.DoubleToSortableInt64(b.Value) + && Exists == b.Exists; } public override int CompareSameType(object other) diff --git a/src/Lucene.Net/Util/Mutable/MutableValueFloat.cs b/src/Lucene.Net/Util/Mutable/MutableValueFloat.cs index 59ff786c56..de6d8cd570 100644 --- a/src/Lucene.Net/Util/Mutable/MutableValueFloat.cs +++ b/src/Lucene.Net/Util/Mutable/MutableValueFloat.cs @@ -1,4 +1,4 @@ -using System.Runtime.CompilerServices; +using System.Runtime.CompilerServices; namespace Lucene.Net.Util.Mutable { @@ -56,7 +56,9 @@ public override MutableValue Duplicate() public override bool EqualsSameType(object other) { MutableValueSingle b = (MutableValueSingle)other; - return Value == b.Value && Exists == b.Exists; + // LUCENENET specific - compare bits rather than using equality operators to prevent these comparisons from failing in x86 in .NET Framework with optimizations enabled + return NumericUtils.SingleToSortableInt32(Value) == NumericUtils.SingleToSortableInt32(b.Value) + && Exists == b.Exists; } public override int CompareSameType(object other) diff --git a/src/Lucene.Net/Util/Packed/PackedInts.cs b/src/Lucene.Net/Util/Packed/PackedInts.cs index 800c599c0b..903d25559f 100644 --- a/src/Lucene.Net/Util/Packed/PackedInts.cs +++ b/src/Lucene.Net/Util/Packed/PackedInts.cs @@ -343,7 +343,8 @@ public static FormatAndBits FastestFormatAndBits(int valueCount, int bitsPerValu { float overhead = Format.PACKED_SINGLE_BLOCK.OverheadPerValue(bpv); float acceptableOverhead = acceptableOverheadPerValue + bitsPerValue - bpv; - if (overhead <= acceptableOverhead) + // LUCENENET specific - compare bits rather than using equality operators to prevent these comparisons from failing in x86 in .NET Framework with optimizations enabled + if (NumericUtils.SingleToSortableInt32(overhead) <= NumericUtils.SingleToSortableInt32(acceptableOverhead)) { actualBitsPerValue = bpv; format = Format.PACKED_SINGLE_BLOCK;