diff --git a/src/coreclr/System.Private.CoreLib/src/System/Reflection/RuntimeCustomAttributeData.cs b/src/coreclr/System.Private.CoreLib/src/System/Reflection/RuntimeCustomAttributeData.cs index e00b0b1854a360..468f71204421f0 100644 --- a/src/coreclr/System.Private.CoreLib/src/System/Reflection/RuntimeCustomAttributeData.cs +++ b/src/coreclr/System.Private.CoreLib/src/System/Reflection/RuntimeCustomAttributeData.cs @@ -1544,11 +1544,13 @@ private static void AddCustomAttributes( else { int data = Unsafe.ReadUnaligned((void*)blobStart); -#if BIGENDIAN - // Metadata is always written in little-endian format. Must account for this on - // big-endian platforms. - data = BinaryPrimitives.ReverseEndianness(data); -#endif + if (!BitConverter.IsLittleEndian) + { + // Metadata is always written in little-endian format. Must account for this on + // big-endian platforms. + data = BinaryPrimitives.ReverseEndianness(data); + } + const int CustomAttributeVersion = 0x0001; if ((data & 0xffff) != CustomAttributeVersion) { diff --git a/src/libraries/System.Private.CoreLib/src/System/String.Comparison.cs b/src/libraries/System.Private.CoreLib/src/System/String.Comparison.cs index 40b9b131ea86f3..67307b508f157a 100644 --- a/src/libraries/System.Private.CoreLib/src/System/String.Comparison.cs +++ b/src/libraries/System.Private.CoreLib/src/System/String.Comparison.cs @@ -884,9 +884,11 @@ internal static unsafe int GetNonRandomizedHashCode(ReadOnlySpan span) case 3: hash1 = BitOperations.RotateLeft(hash1, 5) + hash1 ^ Unsafe.ReadUnaligned(ptr); uint p1 = *(char*)(ptr + 1); -#if BIGENDIAN - p1 <<= 16; -#endif + if (!BitConverter.IsLittleEndian) + { + p1 <<= 16; + } + hash2 = BitOperations.RotateLeft(hash2, 5) + hash2 ^ p1; break; @@ -896,9 +898,11 @@ internal static unsafe int GetNonRandomizedHashCode(ReadOnlySpan span) case 1: uint p0 = *(char*)ptr; -#if BIGENDIAN - p0 <<= 16; -#endif + if (!BitConverter.IsLittleEndian) + { + p0 <<= 16; + } + hash2 = BitOperations.RotateLeft(hash2, 5) + hash2 ^ p0; break; @@ -998,9 +1002,11 @@ internal static unsafe int GetNonRandomizedHashCodeOrdinalIgnoreCase(ReadOnlySpa case 3: p0 = Unsafe.ReadUnaligned(ptr); p1 = *(char*)(ptr + 1); -#if BIGENDIAN - p1 <<= 16; -#endif + if (!BitConverter.IsLittleEndian) + { + p1 <<= 16; + } + if (!Utf16Utility.AllCharsInUInt32AreAscii(p0 | p1)) { goto NotAscii; @@ -1022,9 +1028,11 @@ internal static unsafe int GetNonRandomizedHashCodeOrdinalIgnoreCase(ReadOnlySpa case 1: p0 = *(char*)ptr; -#if BIGENDIAN - p0 <<= 16; -#endif + if (!BitConverter.IsLittleEndian) + { + p0 <<= 16; + } + if (p0 > 0x7f) { goto NotAscii;