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 ed013153d6d21452881836d2ef7d86f10741bac0 Author: Shad Storhaug <[email protected]> AuthorDate: Fri Jul 17 11:57:42 2020 +0700 Lucene.Net.Util.RamUsageEstimator: Switched back to System.Collections.Generic.Dictionary because indexer of JCG dictionary is slower --- src/Lucene.Net/Util/RamUsageEstimator.cs | 36 +++++++++++++++++++------------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/src/Lucene.Net/Util/RamUsageEstimator.cs b/src/Lucene.Net/Util/RamUsageEstimator.cs index d43a55c..f31d9ee 100644 --- a/src/Lucene.Net/Util/RamUsageEstimator.cs +++ b/src/Lucene.Net/Util/RamUsageEstimator.cs @@ -7,6 +7,7 @@ using System.Diagnostics.CodeAnalysis; using System.Globalization; using System.Reflection; using System.Runtime.CompilerServices; +using J2N.Numerics; using JCG = J2N.Collections.Generic; namespace Lucene.Net.Util @@ -60,30 +61,30 @@ namespace Lucene.Net.Util { } - public const int NUM_BYTES_BOOLEAN = 1; - public const int NUM_BYTES_BYTE = 1; - public const int NUM_BYTES_CHAR = 2; + public const int NUM_BYTES_BOOLEAN = sizeof(bool); //1; + public const int NUM_BYTES_BYTE = sizeof(byte); //1; + public const int NUM_BYTES_CHAR = sizeof(char); //2; /// <summary> /// NOTE: This was NUM_BYTES_SHORT in Lucene /// </summary> - public const int NUM_BYTES_INT16 = 2; + public const int NUM_BYTES_INT16 = sizeof(short); //2; /// <summary> /// NOTE: This was NUM_BYTES_INT in Lucene /// </summary> - public const int NUM_BYTES_INT32 = 4; + public const int NUM_BYTES_INT32 = sizeof(int); //4; /// <summary> /// NOTE: This was NUM_BYTES_FLOAT in Lucene /// </summary> - public const int NUM_BYTES_SINGLE = 4; + public const int NUM_BYTES_SINGLE = sizeof(float); //4; /// <summary> /// NOTE: This was NUM_BYTES_LONG in Lucene /// </summary> - public const int NUM_BYTES_INT64 = 8; - public const int NUM_BYTES_DOUBLE = 8; + public const int NUM_BYTES_INT64 = sizeof(long); //8; + public const int NUM_BYTES_DOUBLE = sizeof(double); //8; /// <summary> /// Number of bytes this .NET runtime uses to represent an object reference. @@ -109,7 +110,8 @@ namespace Lucene.Net.Util /// <summary> /// Sizes of primitive classes. /// </summary> - private static readonly IDictionary<Type, int> primitiveSizes = new JCG.Dictionary<Type, int>(IdentityEqualityComparer<Type>.Default) // LUCENENET: Avoid static constructors (see https://github.com/apache/lucenenet/pull/224#issuecomment-469284006) + // LUCENENET specific - Identity comparer is not necessary here because Type is already representing an identity + private static readonly IDictionary<Type, int> primitiveSizes = new Dictionary<Type, int>(/*IdentityEqualityComparer<Type>.Default*/) // LUCENENET: Avoid static constructors (see https://github.com/apache/lucenenet/pull/224#issuecomment-469284006) { [typeof(bool)] = NUM_BYTES_BOOLEAN, [typeof(sbyte)] = NUM_BYTES_BYTE, @@ -634,7 +636,7 @@ namespace Lucene.Net.Util Type type = f.FieldType; int fsize = 0; - if (!typeof(IntPtr).Equals(type) && !typeof(UIntPtr).Equals(type)) + if (!(typeof(IntPtr) == type) && !(typeof(UIntPtr) == type)) fsize = type.IsPrimitive ? primitiveSizes[type] : NUM_BYTES_OBJECT_REF; // LUCENENET NOTE: I dont think this will ever not be null @@ -842,11 +844,15 @@ namespace Lucene.Net.Util private static int Rehash(object o) { int k = RuntimeHelpers.GetHashCode(o); - k ^= (int)((uint)k >> 16); - k *= unchecked((int)0x85ebca6b); - k ^= (int)((uint)k >> 13); - k *= unchecked((int)0xc2b2ae35); - k ^= (int)((uint)k >> 16); + unchecked + { + k ^= k.TripleShift(16); + k *= (int)0x85ebca6b; + k ^= k.TripleShift(13); + k *= (int)0xc2b2ae35; + k ^= k.TripleShift(16); + } + return k; }
