Skip to content

Commit 0976c0c

Browse files
authored
Lucene.Net.Search.Similarities.SimilarityBase::Log2(): Use the J2N.MathExtensions.Log2() method, which may be hardware optimized. (#1206)
1 parent 2abc120 commit 0976c0c

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

src/Lucene.Net/Search/Similarities/SimilarityBase.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using Lucene.Net.Diagnostics;
22
using System;
3+
using System.Runtime.CompilerServices;
34
using AtomicReaderContext = Lucene.Net.Index.AtomicReaderContext;
45
using BytesRef = Lucene.Net.Util.BytesRef;
56
using FieldInvertState = Lucene.Net.Index.FieldInvertState;
@@ -43,9 +44,7 @@ namespace Lucene.Net.Search.Similarities
4344
/// </summary>
4445
public abstract class SimilarityBase : Similarity
4546
{
46-
/// <summary>
47-
/// For <see cref="Log2(double)"/>. Precomputed for efficiency reasons. </summary>
48-
private static readonly double LOG_2 = Math.Log(2);
47+
// LUCENENET specific - pre-computed LOG_2 value not needed because we are using J2N.MathExtensions.Log2() instead, which may be hardware optimized
4948

5049
/// <summary>
5150
/// True if overlap tokens (tokens with a position of increment of zero) are
@@ -272,10 +271,11 @@ protected internal virtual byte EncodeNormValue(float boost, float length)
272271

273272
/// <summary>
274273
/// Returns the base two logarithm of <c>x</c>. </summary>
274+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
275275
public static double Log2(double x)
276276
{
277277
// Put this to a 'util' class if we need more of these.
278-
return Math.Log(x) / LOG_2;
278+
return J2N.MathExtensions.Log2(x); // LUCENENET: Use hardware-optimized Log2() method, when available
279279
}
280280

281281
// --------------------------------- Classes ---------------------------------

0 commit comments

Comments
 (0)