From 57214f1948e56835cde1b6162acc58751f483e14 Mon Sep 17 00:00:00 2001 From: Jan Kotas Date: Fri, 30 Jun 2017 22:23:26 -0700 Subject: [PATCH] Reducing diffs with CoreRT (#12579) * Rename m_firstChar to _firstChar to reduce CoreRT diffs * Reducing diffs with CoreRT * Delete dead code --- src/mscorlib/src/System/Globalization/Calendar.cs | 13 +---- src/mscorlib/src/System/Guid.cs | 4 +- src/mscorlib/src/System/String.Comparison.cs | 28 +++++----- src/mscorlib/src/System/String.Manipulation.cs | 48 ++++++++--------- src/mscorlib/src/System/String.Searching.cs | 4 +- src/mscorlib/src/System/String.cs | 42 +++++++-------- src/mscorlib/src/System/TimeSpan.cs | 63 +---------------------- src/vm/mscorlib.h | 2 +- 8 files changed, 66 insertions(+), 138 deletions(-) diff --git a/src/mscorlib/src/System/Globalization/Calendar.cs b/src/mscorlib/src/System/Globalization/Calendar.cs index 86782c1..e6ab247 100644 --- a/src/mscorlib/src/System/Globalization/Calendar.cs +++ b/src/mscorlib/src/System/Globalization/Calendar.cs @@ -28,7 +28,7 @@ namespace System.Globalization // The calculation of hour/minute/second is moved to Calendar from GregorianCalendar, // since most of the calendars (or all?) have the same way of calcuating hour/minute/second. - public abstract partial class Calendar : ICloneable + public abstract class Calendar : ICloneable { // Number of 100ns (10E-7 second) ticks per time unit internal const long TicksPerMillisecond = 10000; @@ -59,19 +59,8 @@ namespace System.Globalization private int _currentEraValue = -1; - [OptionalField(VersionAdded = 2)] private bool _isReadOnly = false; -#if CORECLR - internal const CalendarId CAL_HEBREW = CalendarId.HEBREW; - internal const CalendarId CAL_HIJRI = CalendarId.HIJRI; - internal const CalendarId CAL_JAPAN = CalendarId.JAPAN; - internal const CalendarId CAL_JULIAN = CalendarId.JULIAN; - internal const CalendarId CAL_TAIWAN = CalendarId.TAIWAN; - internal const CalendarId CAL_UMALQURA = CalendarId.UMALQURA; - internal const CalendarId CAL_PERSIAN = CalendarId.PERSIAN; -#endif - // The minimum supported DateTime range for the calendar. public virtual DateTime MinSupportedDateTime diff --git a/src/mscorlib/src/System/Guid.cs b/src/mscorlib/src/System/Guid.cs index e3b3a6f..aad188b 100644 --- a/src/mscorlib/src/System/Guid.cs +++ b/src/mscorlib/src/System/Guid.cs @@ -701,7 +701,7 @@ namespace System } else { - char upperCaseCh = Char.ToUpper(ch, CultureInfo.InvariantCulture); + char upperCaseCh = Char.ToUpperInvariant(ch); if (upperCaseCh >= 'A' && upperCaseCh <= 'F') { continue; @@ -982,7 +982,7 @@ namespace System private static bool IsHexPrefix(String str, int i) { - if (str.Length > i + 1 && str[i] == '0' && (Char.ToLower(str[i + 1], CultureInfo.InvariantCulture) == 'x')) + if (str.Length > i + 1 && str[i] == '0' && (Char.ToLowerInvariant(str[i + 1]) == 'x')) return true; else return false; diff --git a/src/mscorlib/src/System/String.Comparison.cs b/src/mscorlib/src/System/String.Comparison.cs index c2c3a87..7316322 100644 --- a/src/mscorlib/src/System/String.Comparison.cs +++ b/src/mscorlib/src/System/String.Comparison.cs @@ -25,7 +25,7 @@ namespace System Contract.EndContractBlock(); int length = Math.Min(strA.Length, strB.Length); - fixed (char* ap = &strA.m_firstChar) fixed (char* bp = &strB.m_firstChar) + fixed (char* ap = &strA._firstChar) fixed (char* bp = &strB._firstChar) { char* a = ap; char* b = bp; @@ -85,7 +85,7 @@ namespace System int length = strA.Length; - fixed (char* ap = &strA.m_firstChar) fixed (char* bp = &strB.m_firstChar) + fixed (char* ap = &strA._firstChar) fixed (char* bp = &strB._firstChar) { char* a = ap; char* b = bp; @@ -145,7 +145,7 @@ namespace System Contract.EndContractBlock(); int length = strA.Length; - fixed (char* ap = &strA.m_firstChar) fixed (char* bp = &strB.m_firstChar) + fixed (char* ap = &strA._firstChar) fixed (char* bp = &strB._firstChar) { char* a = ap; char* b = bp; @@ -187,7 +187,7 @@ namespace System int length = startsWith.Length; - fixed (char* ap = &str.m_firstChar) fixed (char* bp = &startsWith.m_firstChar) + fixed (char* ap = &str._firstChar) fixed (char* bp = &startsWith._firstChar) { char* a = ap; char* b = bp; @@ -241,19 +241,19 @@ namespace System // NOTE: This may be subject to change if eliminating the check // in the callers makes them small enough to be inlined by the JIT - Debug.Assert(strA.m_firstChar == strB.m_firstChar, + Debug.Assert(strA._firstChar == strB._firstChar, "For performance reasons, callers of this method should " + "check/short-circuit beforehand if the first char is the same."); int length = Math.Min(strA.Length, strB.Length); - fixed (char* ap = &strA.m_firstChar) fixed (char* bp = &strB.m_firstChar) + fixed (char* ap = &strA._firstChar) fixed (char* bp = &strB._firstChar) { char* a = ap; char* b = bp; // Check if the second chars are different here - // The reason we check if m_firstChar is different is because + // The reason we check if _firstChar is different is because // it's the most common case and allows us to avoid a method call // to here. // The reason we check if the second char is different is because @@ -422,9 +422,9 @@ namespace System case StringComparison.Ordinal: // Most common case: first character is different. // Returns false for empty strings. - if (strA.m_firstChar != strB.m_firstChar) + if (strA._firstChar != strB._firstChar) { - return strA.m_firstChar - strB.m_firstChar; + return strA._firstChar - strB._firstChar; } return CompareOrdinalHelper(strA, strB); @@ -659,9 +659,9 @@ namespace System // Most common case, first character is different. // This will return false for empty strings. - if (strA.m_firstChar != strB.m_firstChar) + if (strA._firstChar != strB._firstChar) { - return strA.m_firstChar - strB.m_firstChar; + return strA._firstChar - strB._firstChar; } return CompareOrdinalHelper(strA, strB); @@ -1048,7 +1048,7 @@ namespace System { unsafe { - fixed (char* src = &m_firstChar) + fixed (char* src = &_firstChar) { Debug.Assert(src[this.Length] == '\0', "src[this.Length] == '\\0'"); Debug.Assert(((int)src) % 4 == 0, "Managed string should start at 4 bytes boundary"); @@ -1152,7 +1152,7 @@ namespace System return CultureInfo.InvariantCulture.CompareInfo.IsPrefix(this, value, CompareOptions.IgnoreCase); case StringComparison.Ordinal: - if (this.Length < value.Length || m_firstChar != value.m_firstChar) + if (this.Length < value.Length || _firstChar != value._firstChar) { return false; } @@ -1197,6 +1197,6 @@ namespace System } [Pure] - public bool StartsWith(char value) => Length != 0 && m_firstChar == value; + public bool StartsWith(char value) => Length != 0 && _firstChar == value; } } diff --git a/src/mscorlib/src/System/String.Manipulation.cs b/src/mscorlib/src/System/String.Manipulation.cs index ac1f61c..ba78a94 100644 --- a/src/mscorlib/src/System/String.Manipulation.cs +++ b/src/mscorlib/src/System/String.Manipulation.cs @@ -24,8 +24,8 @@ namespace System } Contract.EndContractBlock(); - fixed (char* pDest = &dest.m_firstChar) - fixed (char* pSrc = &src.m_firstChar) + fixed (char* pDest = &dest._firstChar) + fixed (char* pSrc = &src._firstChar) { wstrcpy(pDest + destPos, pSrc, src.Length); } @@ -508,11 +508,11 @@ namespace System String result = FastAllocateString(newLength); unsafe { - fixed (char* srcThis = &m_firstChar) + fixed (char* srcThis = &_firstChar) { - fixed (char* srcInsert = &value.m_firstChar) + fixed (char* srcInsert = &value._firstChar) { - fixed (char* dst = &result.m_firstChar) + fixed (char* dst = &result._firstChar) { wstrcpy(dst, srcThis, startIndex); wstrcpy(dst + startIndex, srcInsert, insertLength); @@ -566,7 +566,7 @@ namespace System public unsafe static string Join(string separator, params object[] values) { separator = separator ?? string.Empty; - fixed (char* pSeparator = &separator.m_firstChar) + fixed (char* pSeparator = &separator._firstChar) { // Defer argument validation to the internal function return JoinCore(pSeparator, separator.Length, values); @@ -576,7 +576,7 @@ namespace System public unsafe static string Join(string separator, IEnumerable values) { separator = separator ?? string.Empty; - fixed (char* pSeparator = &separator.m_firstChar) + fixed (char* pSeparator = &separator._firstChar) { // Defer argument validation to the internal function return JoinCore(pSeparator, separator.Length, values); @@ -625,7 +625,7 @@ namespace System public unsafe static string Join(string separator, string[] value, int startIndex, int count) { separator = separator ?? string.Empty; - fixed (char* pSeparator = &separator.m_firstChar) + fixed (char* pSeparator = &separator._firstChar) { // Defer argument validation to the internal function return JoinCore(pSeparator, separator.Length, value, startIndex, count); @@ -801,7 +801,7 @@ namespace System if (i < end - 1) { // Fill in the separator. - fixed (char* pResult = &result.m_firstChar) + fixed (char* pResult = &result._firstChar) { // If we are called from the char-based overload, we will not // want to call MemoryCopy each time we fill in the separator. So @@ -848,11 +848,11 @@ namespace System String result = FastAllocateString(totalWidth); unsafe { - fixed (char* dst = &result.m_firstChar) + fixed (char* dst = &result._firstChar) { for (int i = 0; i < count; i++) dst[i] = paddingChar; - fixed (char* src = &m_firstChar) + fixed (char* src = &_firstChar) { wstrcpy(dst + count, src, oldLength); } @@ -879,9 +879,9 @@ namespace System String result = FastAllocateString(totalWidth); unsafe { - fixed (char* dst = &result.m_firstChar) + fixed (char* dst = &result._firstChar) { - fixed (char* src = &m_firstChar) + fixed (char* src = &_firstChar) { wstrcpy(dst, src, oldLength); } @@ -916,9 +916,9 @@ namespace System String result = FastAllocateString(newLength); unsafe { - fixed (char* src = &m_firstChar) + fixed (char* src = &_firstChar) { - fixed (char* dst = &result.m_firstChar) + fixed (char* dst = &result._firstChar) { wstrcpy(dst, src, startIndex); wstrcpy(dst + startIndex, src + startIndex + count, newLength - startIndex); @@ -1055,7 +1055,7 @@ namespace System { int remainingLength = Length; - fixed (char* pChars = &m_firstChar) + fixed (char* pChars = &_firstChar) { char* pSrc = pChars; @@ -1076,9 +1076,9 @@ namespace System String result = FastAllocateString(Length); - fixed (char* pChars = &m_firstChar) + fixed (char* pChars = &_firstChar) { - fixed (char* pResult = &result.m_firstChar) + fixed (char* pResult = &result._firstChar) { int copyLength = Length - remainingLength; @@ -1436,7 +1436,7 @@ namespace System if (separators == null || separatorsLength == 0) { - fixed (char* pwzChars = &m_firstChar) + fixed (char* pwzChars = &_firstChar) { //If they passed null or an empty string, look for whitespace. for (int i = 0; i < Length && foundCount < sepList.Length; i++) @@ -1452,7 +1452,7 @@ namespace System { int sepListCount = sepList.Length; //If they passed in a string of chars, actually look for those chars. - fixed (char* pwzChars = &m_firstChar) + fixed (char* pwzChars = &_firstChar) { for (int i = 0; i < Length && foundCount < sepListCount; i++) { @@ -1485,7 +1485,7 @@ namespace System int sepListCount = sepList.Length; int currentSepLength = separator.Length; - fixed (char* pwzChars = &m_firstChar) + fixed (char* pwzChars = &_firstChar) { for (int i = 0; i < Length && foundCount < sepListCount; i++) { @@ -1519,7 +1519,7 @@ namespace System int sepListCount = sepList.Length; int sepCount = separators.Length; - fixed (char* pwzChars = &m_firstChar) + fixed (char* pwzChars = &_firstChar) { for (int i = 0; i < Length && foundCount < sepListCount; i++) { @@ -1602,8 +1602,8 @@ namespace System String result = FastAllocateString(length); - fixed (char* dest = &result.m_firstChar) - fixed (char* src = &m_firstChar) + fixed (char* dest = &result._firstChar) + fixed (char* src = &_firstChar) { wstrcpy(dest, src + startIndex, length); } diff --git a/src/mscorlib/src/System/String.Searching.cs b/src/mscorlib/src/System/String.Searching.cs index 388b5e1..22e2a80 100644 --- a/src/mscorlib/src/System/String.Searching.cs +++ b/src/mscorlib/src/System/String.Searching.cs @@ -46,7 +46,7 @@ namespace System if (count < 0 || count > Length - startIndex) throw new ArgumentOutOfRangeException(nameof(count), SR.ArgumentOutOfRange_Count); - fixed (char* pChars = &m_firstChar) + fixed (char* pChars = &_firstChar) { char* pCh = pChars + startIndex; @@ -225,7 +225,7 @@ namespace System if (count < 0 || count - 1 > startIndex) throw new ArgumentOutOfRangeException(nameof(count), SR.ArgumentOutOfRange_Count); - fixed (char* pChars = &m_firstChar) + fixed (char* pChars = &_firstChar) { char* pCh = pChars + startIndex; diff --git a/src/mscorlib/src/System/String.cs b/src/mscorlib/src/System/String.cs index c2b7466..a34ea21 100644 --- a/src/mscorlib/src/System/String.cs +++ b/src/mscorlib/src/System/String.cs @@ -52,7 +52,7 @@ namespace System // For empty strings, this will be '\0' since // strings are both null-terminated and length prefixed - [NonSerialized] private char m_firstChar; + [NonSerialized] private char _firstChar; // The Empty constant holds the empty string value. It is initialized by the EE during startup. // It is treated as intrinsic by the JIT as so the static constructor would never run. @@ -63,7 +63,7 @@ namespace System //from native. public static readonly String Empty; - internal char FirstChar { get { return m_firstChar; } } + internal char FirstChar { get { return _firstChar; } } // // This is a helper method for the security team. They need to uppercase some strings (guaranteed to be less // than 0x80) before security is fully initialized. Without security initialized, we can't grab resources (the nlp's) @@ -81,7 +81,7 @@ namespace System // int length = strIn.Length; String strOut = FastAllocateString(length); - fixed (char* inBuff = &strIn.m_firstChar, outBuff = &strOut.m_firstChar) + fixed (char* inBuff = &strIn._firstChar, outBuff = &strOut._firstChar) { for (int i = 0; i < length; i++) { @@ -131,7 +131,7 @@ namespace System // Note: fixed does not like empty arrays if (count > 0) { - fixed (char* src = &m_firstChar) + fixed (char* src = &_firstChar) fixed (char* dest = destination) wstrcpy(dest + destinationIndex, src + sourceIndex, count); } @@ -144,7 +144,7 @@ namespace System if (length > 0) { char[] chars = new char[length]; - fixed (char* src = &m_firstChar) fixed (char* dest = chars) + fixed (char* src = &_firstChar) fixed (char* dest = chars) { wstrcpy(dest, src, length); } @@ -168,7 +168,7 @@ namespace System if (length > 0) { char[] chars = new char[length]; - fixed (char* src = &m_firstChar) fixed (char* dest = chars) + fixed (char* src = &_firstChar) fixed (char* dest = chars) { wstrcpy(dest, src + startIndex, length); } @@ -277,7 +277,7 @@ namespace System return String.Empty; String s = FastAllocateString(stringLength); - fixed (char* pTempChars = &s.m_firstChar) + fixed (char* pTempChars = &s._firstChar) { int doubleCheck = encoding.GetChars(bytes, byteLength, pTempChars, stringLength, null); Debug.Assert(stringLength == doubleCheck, @@ -288,19 +288,19 @@ namespace System } // This is only intended to be used by char.ToString. - // It is necessary to put the code in this class instead of Char, since m_firstChar is a private member. - // Making m_firstChar internal would be dangerous since it would make it much easier to break String's immutability. + // It is necessary to put the code in this class instead of Char, since _firstChar is a private member. + // Making _firstChar internal would be dangerous since it would make it much easier to break String's immutability. internal static string CreateFromChar(char c) { string result = FastAllocateString(1); - result.m_firstChar = c; + result._firstChar = c; return result; } unsafe internal int GetBytesFromEncoding(byte* pbNativeBuffer, int cbNativeBuffer, Encoding encoding) { // encoding == Encoding.UTF8 - fixed (char* pwzChar = &m_firstChar) + fixed (char* pwzChar = &_firstChar) { return encoding.GetBytes(pwzChar, m_stringLength, pbNativeBuffer, cbNativeBuffer); } @@ -318,7 +318,7 @@ namespace System uint flgs = (fBestFit ? 0 : WC_NO_BEST_FIT_CHARS); uint DefaultCharUsed = 0; - fixed (char* pwzChar = &m_firstChar) + fixed (char* pwzChar = &_firstChar) { nb = Win32Native.WideCharToMultiByte( CP_ACP, @@ -412,7 +412,7 @@ namespace System unsafe { - fixed (char* dest = &result.m_firstChar, source = value) + fixed (char* dest = &result._firstChar, source = value) { wstrcpy(dest, source, value.Length); } @@ -444,7 +444,7 @@ namespace System unsafe { - fixed (char* dest = &result.m_firstChar, source = value) + fixed (char* dest = &result._firstChar, source = value) { wstrcpy(dest, source + startIndex, length); } @@ -464,7 +464,7 @@ namespace System { unsafe { - fixed (char* dest = &result.m_firstChar) + fixed (char* dest = &result._firstChar) { char* dmem = dest; while (((uint)dmem & 3) != 0 && count > 0) @@ -615,7 +615,7 @@ namespace System return String.Empty; String result = FastAllocateString(count); - fixed (char* dest = &result.m_firstChar) + fixed (char* dest = &result._firstChar) wstrcpy(dest, ptr, count); return result; } @@ -653,7 +653,7 @@ namespace System try { - fixed (char* dest = &result.m_firstChar) + fixed (char* dest = &result._firstChar) wstrcpy(dest, pFrom, length); return result; } @@ -704,8 +704,8 @@ namespace System String result = FastAllocateString(length); - fixed (char* dest = &result.m_firstChar) - fixed (char* src = &str.m_firstChar) + fixed (char* dest = &result._firstChar) + fixed (char* src = &str._firstChar) { wstrcpy(dest, src, length); } @@ -869,7 +869,7 @@ namespace System { if (len == 0) return; - fixed (char* charPtr = &src.m_firstChar) + fixed (char* charPtr = &src._firstChar) { byte* srcPtr = (byte*)charPtr; byte* dstPtr = (byte*)dest; @@ -879,7 +879,7 @@ namespace System internal ref char GetRawStringData() { - return ref m_firstChar; + return ref _firstChar; } } } diff --git a/src/mscorlib/src/System/TimeSpan.cs b/src/mscorlib/src/System/TimeSpan.cs index ca60bcb..e1237da 100644 --- a/src/mscorlib/src/System/TimeSpan.cs +++ b/src/mscorlib/src/System/TimeSpan.cs @@ -378,14 +378,7 @@ namespace System } public String ToString(String format, IFormatProvider formatProvider) { - if (LegacyMode) - { - return TimeSpanFormat.Format(this, null, null); - } - else - { - return TimeSpanFormat.Format(this, format, formatProvider); - } + return TimeSpanFormat.Format(this, format, formatProvider); } #endregion @@ -482,59 +475,5 @@ namespace System { return t1._ticks >= t2._ticks; } - - - // - // In .NET Framework v1.0 - v3.5 System.TimeSpan did not implement IFormattable - // The composite formatter ignores format specifiers on types that do not implement - // IFormattable, so the following code would 'just work' by using TimeSpan.ToString() - // under the hood: - // String.Format("{0:_someRandomFormatString_}", myTimeSpan); - // - // In .NET Framework v4.0 System.TimeSpan implements IFormattable. This causes the - // composite formatter to call TimeSpan.ToString(string format, FormatProvider provider) - // and pass in "_someRandomFormatString_" for the format parameter. When the format - // parameter is invalid a FormatException is thrown. - // - // The 'NetFx40_TimeSpanLegacyFormatMode' per-AppDomain configuration option and the 'TimeSpan_LegacyFormatMode' - // process-wide configuration option allows applications to run with the v1.0 - v3.5 legacy behavior. When - // either switch is specified the format parameter is ignored and the default output is returned. - // - // There are three ways to use the process-wide configuration option: - // - // 1) Config file (MyApp.exe.config) - // - // - // - // - // - // - // 2) Environment variable - // set COMPlus_TimeSpan_LegacyFormatMode=1 - // 3) RegistryKey - // [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework] - // "TimeSpan_LegacyFormatMode"=dword:00000001 - // - private static bool GetLegacyFormatMode() - { - return false; - } - - private static volatile bool _legacyConfigChecked; - private static volatile bool _legacyMode; - - private static bool LegacyMode - { - get - { - if (!_legacyConfigChecked) - { - // no need to lock - idempotent - _legacyMode = GetLegacyFormatMode(); - _legacyConfigChecked = true; - } - return _legacyMode; - } - } } } diff --git a/src/vm/mscorlib.h b/src/vm/mscorlib.h index 24c87f3..cd3bdee 100644 --- a/src/vm/mscorlib.h +++ b/src/vm/mscorlib.h @@ -872,7 +872,7 @@ DEFINE_CLASS(BITCONVERTER, System, BitConverter) DEFINE_FIELD(BITCONVERTER, ISLITTLEENDIAN, IsLittleEndian) // Defined as element type alias // DEFINE_CLASS(STRING, System, String) -DEFINE_FIELD(STRING, M_FIRST_CHAR, m_firstChar) +DEFINE_FIELD(STRING, M_FIRST_CHAR, _firstChar) DEFINE_FIELD(STRING, EMPTY, Empty) DEFINE_METHOD(STRING, CREATE_STRING, CreateString, SM_PtrSByt_Int_Int_Encoding_RetStr) DEFINE_METHOD(STRING, CTOR_CHARPTR, .ctor, IM_PtrChar_RetVoid) -- 2.7.4