This is an automated email from the ASF dual-hosted git repository. nightowl888 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/lucenenet.git
commit 40186fb11433d97ab118a5ec91c4e8892bbf32ea Author: Shad Storhaug <[email protected]> AuthorDate: Wed Jul 1 02:11:48 2020 +0700 Lucene.Net.Util (MathUtil + NumericUtils + SloppyMath + UnicodeUtil): Added some aggressive inlining, made classes static (#261) --- src/Lucene.Net/Util/MathUtil.cs | 13 +++++++------ src/Lucene.Net/Util/NumericUtils.cs | 17 ++++++++++++----- src/Lucene.Net/Util/SloppyMath.cs | 4 +++- src/Lucene.Net/Util/UnicodeUtil.cs | 4 ++++ 4 files changed, 26 insertions(+), 12 deletions(-) diff --git a/src/Lucene.Net/Util/MathUtil.cs b/src/Lucene.Net/Util/MathUtil.cs index 1c6139a..1331fea 100644 --- a/src/Lucene.Net/Util/MathUtil.cs +++ b/src/Lucene.Net/Util/MathUtil.cs @@ -1,5 +1,6 @@ using J2N.Numerics; using System; +using System.Runtime.CompilerServices; namespace Lucene.Net.Util { @@ -23,16 +24,12 @@ namespace Lucene.Net.Util /// <summary> /// Math static utility methods. /// </summary> - public sealed class MathUtil + public static class MathUtil // LUCENENET: Changed to static { - // No instance: - private MathUtil() - { - } - /// <summary> /// Returns <c>x <= 0 ? 0 : Math.Floor(Math.Log(x) / Math.Log(base))</c>. </summary> /// <param name="base"> Must be <c>> 1</c>.</param> + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int Log(long x, int @base) { if (@base <= 1) @@ -51,6 +48,7 @@ namespace Lucene.Net.Util /// <summary> /// Calculates logarithm in a given <paramref name="base"/> with doubles. /// </summary> + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static double Log(double @base, double x) { return Math.Log(x) / Math.Log(@base); @@ -113,6 +111,7 @@ namespace Lucene.Net.Util /// <item><description>If the argument is infinite, then the result is infinity with the same sign as the argument.</description></item> /// </list> /// </summary> + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static double Asinh(double a) { double sign; @@ -141,6 +140,7 @@ namespace Lucene.Net.Util /// <item><description>If the argument is less than 1, then the result is NaN.</description></item> /// </list> /// </summary> + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static double Acosh(double a) { return Math.Log(Math.Sqrt(a * a - 1.0d) + a); @@ -158,6 +158,7 @@ namespace Lucene.Net.Util /// <item><description>If the argument's absolute value is greater than 1, then the result is NaN.</description></item> /// </list> /// </summary> + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static double Atanh(double a) { double mult; diff --git a/src/Lucene.Net/Util/NumericUtils.cs b/src/Lucene.Net/Util/NumericUtils.cs index 13750b7..b983650 100644 --- a/src/Lucene.Net/Util/NumericUtils.cs +++ b/src/Lucene.Net/Util/NumericUtils.cs @@ -1,5 +1,6 @@ using J2N.Numerics; using System; +using System.Runtime.CompilerServices; namespace Lucene.Net.Util { @@ -60,12 +61,8 @@ namespace Lucene.Net.Util /// @lucene.internal /// @since 2.9, API changed non backwards-compliant in 4.0 /// </summary> - public sealed class NumericUtils + public static class NumericUtils // LUCENENET specific - changed to static { - private NumericUtils() // no instance! - { - } - /// <summary> /// The default precision step used by <see cref="Documents.Int32Field"/>, /// <see cref="Documents.SingleField"/>, <see cref="Documents.Int64Field"/>, @@ -118,6 +115,7 @@ namespace Lucene.Net.Util /// <param name="val"> The numeric value </param> /// <param name="shift"> How many bits to strip from the right </param> /// <param name="bytes"> Will contain the encoded value </param> + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void Int64ToPrefixCoded(long val, int shift, BytesRef bytes) { Int64ToPrefixCodedBytes(val, shift, bytes); @@ -133,6 +131,7 @@ namespace Lucene.Net.Util /// <param name="val"> The numeric value </param> /// <param name="shift"> How many bits to strip from the right </param> /// <param name="bytes"> Will contain the encoded value </param> + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void Int32ToPrefixCoded(int val, int shift, BytesRef bytes) { Int32ToPrefixCodedBytes(val, shift, bytes); @@ -215,6 +214,7 @@ namespace Lucene.Net.Util /// </summary> /// <exception cref="FormatException"> if the supplied <see cref="BytesRef"/> is /// not correctly prefix encoded. </exception> + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int GetPrefixCodedInt64Shift(BytesRef val) { int shift = val.Bytes[val.Offset] - SHIFT_START_INT64; @@ -232,6 +232,7 @@ namespace Lucene.Net.Util /// </summary> /// <exception cref="FormatException"> if the supplied <see cref="BytesRef"/> is /// not correctly prefix encoded. </exception> + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int GetPrefixCodedInt32Shift(BytesRef val) { int shift = val.Bytes[val.Offset] - SHIFT_START_INT32; @@ -305,6 +306,7 @@ namespace Lucene.Net.Util /// NOTE: This was doubleToSortableLong() in Lucene /// </summary> /// <seealso cref="SortableInt64ToDouble(long)"/> + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long DoubleToSortableInt64(double val) { long f = J2N.BitConversion.DoubleToInt64Bits(val); @@ -321,6 +323,7 @@ namespace Lucene.Net.Util /// NOTE: This was sortableLongToDouble() in Lucene /// </summary> /// <seealso cref="DoubleToSortableInt64(double)"/> + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static double SortableInt64ToDouble(long val) { if (val < 0) @@ -341,6 +344,7 @@ namespace Lucene.Net.Util /// NOTE: This was floatToSortableInt() in Lucene /// </summary> /// <seealso cref="SortableInt32ToSingle(int)"/> + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int SingleToSortableInt32(float val) { int f = J2N.BitConversion.SingleToInt32Bits(val); @@ -357,6 +361,7 @@ namespace Lucene.Net.Util /// NOTE: This was sortableIntToFloat() in Lucene /// </summary> /// <seealso cref="SingleToSortableInt32"/> + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float SortableInt32ToSingle(int val) { if (val < 0) @@ -377,6 +382,7 @@ namespace Lucene.Net.Util /// <para/> /// NOTE: This was splitLongRange() in Lucene /// </summary> + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void SplitInt64Range(Int64RangeBuilder builder, int precisionStep, long minBound, long maxBound) { SplitRange(builder, 64, precisionStep, minBound, maxBound); @@ -393,6 +399,7 @@ namespace Lucene.Net.Util /// <para/> /// NOTE: This was splitIntRange() in Lucene /// </summary> + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void SplitInt32Range(Int32RangeBuilder builder, int precisionStep, int minBound, int maxBound) { SplitRange(builder, 32, precisionStep, minBound, maxBound); diff --git a/src/Lucene.Net/Util/SloppyMath.cs b/src/Lucene.Net/Util/SloppyMath.cs index cb9d0b2..696c974 100644 --- a/src/Lucene.Net/Util/SloppyMath.cs +++ b/src/Lucene.Net/Util/SloppyMath.cs @@ -1,5 +1,6 @@ using J2N; using System; +using System.Runtime.CompilerServices; namespace Lucene.Net.Util { @@ -34,7 +35,7 @@ namespace Lucene.Net.Util /// <summary> /// Math functions that trade off accuracy for speed. </summary> - public class SloppyMath + public static class SloppyMath // LUCENENET: Changed to static { /// <summary> /// Returns the distance in kilometers between two points @@ -158,6 +159,7 @@ namespace Lucene.Net.Util /// <summary> /// Return an approximate value of the diameter of the earth at the given latitude, in kilometers. </summary> + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static double EarthDiameter(double latitude) { if(double.IsNaN(latitude)) diff --git a/src/Lucene.Net/Util/UnicodeUtil.cs b/src/Lucene.Net/Util/UnicodeUtil.cs index bdb1482..fe0dd16 100644 --- a/src/Lucene.Net/Util/UnicodeUtil.cs +++ b/src/Lucene.Net/Util/UnicodeUtil.cs @@ -2,6 +2,7 @@ using J2N; using J2N.Text; using System; using System.Diagnostics; +using System.Runtime.CompilerServices; using System.Text; namespace Lucene.Net.Util @@ -571,6 +572,7 @@ namespace Lucene.Net.Util /// </summary> /// <exception cref="ArgumentException"> If invalid codepoint header byte occurs or the /// content is prematurely truncated. </exception> + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int CodePointCount(BytesRef utf8) { int pos = utf8.Offset; @@ -696,6 +698,7 @@ namespace Lucene.Net.Util /// <returns> a String representing the code points between offset and count. </returns> /// <exception cref="ArgumentException"> If an invalid code point is encountered. </exception> /// <exception cref="IndexOutOfRangeException"> If the offset or count are out of bounds. </exception> + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string NewString(int[] codePoints, int offset, int count) { char[] chars = ToCharArray(codePoints, offset, count); @@ -862,6 +865,7 @@ namespace Lucene.Net.Util /// <summary> /// Utility method for <see cref="UTF8toUTF16(byte[], int, int, CharsRef)"/> </summary> /// <seealso cref="UTF8toUTF16(byte[], int, int, CharsRef)"/> + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void UTF8toUTF16(BytesRef bytesRef, CharsRef chars) { UTF8toUTF16(bytesRef.Bytes, bytesRef.Offset, bytesRef.Length, chars);
