Skip to content

Commit

Permalink
Cleanup dead code under undefined constants (dotnet#39155)
Browse files Browse the repository at this point in the history
  • Loading branch information
am11 authored Jul 12, 2020
1 parent 1b8d1dc commit b3c7002
Show file tree
Hide file tree
Showing 13 changed files with 22 additions and 502 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,131 +34,6 @@ internal static bool IsValueType<T>()
#endif
}

#if EqualsStructurally

/// <summary>
/// An optimized version of <see cref="Enumerable.SequenceEqual{T}(IEnumerable{T}, IEnumerable{T}, IEqualityComparer{T})"/>
/// that allows nulls, considers reference equality and count before beginning the enumeration.
/// </summary>
/// <typeparam name="T">The type of elements in the sequence.</typeparam>
/// <param name="sequence1">The first sequence.</param>
/// <param name="sequence2">The second sequence.</param>
/// <param name="equalityComparer">The equality comparer to use for the elements.</param>
/// <returns><c>true</c> if the sequences are equal (same elements in the same order); <c>false</c> otherwise.</returns>
internal static bool CollectionEquals<T>(this IEnumerable<T> sequence1, IEnumerable<T> sequence2, IEqualityComparer<T> equalityComparer = null)
{
if (sequence1 == sequence2)
{
return true;
}

if ((sequence1 == null) ^ (sequence2 == null))
{
return false;
}

int count1, count2;
if (sequence1.TryGetCount(out count1) && sequence2.TryGetCount(out count2))
{
if (count1 != count2)
{
return false;
}

if (count1 == 0 && count2 == 0)
{
return true;
}
}

return sequence1.SequenceEqual(sequence2, equalityComparer);
}

/// <summary>
/// An optimized version of <see cref="Enumerable.SequenceEqual{T}(IEnumerable{T}, IEnumerable{T}, IEqualityComparer{T})"/>
/// that allows nulls, considers reference equality and count before beginning the enumeration.
/// </summary>
/// <typeparam name="T">The type of elements in the sequence.</typeparam>
/// <param name="sequence1">The first sequence.</param>
/// <param name="sequence2">The second sequence.</param>
/// <param name="equalityComparer">The equality comparer to use for the elements.</param>
/// <returns><c>true</c> if the sequences are equal (same elements in the same order); <c>false</c> otherwise.</returns>
internal static bool CollectionEquals<T>(this IEnumerable<T> sequence1, IEnumerable sequence2, IEqualityComparer equalityComparer = null)
{
if (sequence1 == sequence2)
{
return true;
}

if ((sequence1 == null) ^ (sequence2 == null))
{
return false;
}

int count1, count2;
if (sequence1.TryGetCount(out count1) && sequence2.TryGetCount<T>(out count2))
{
if (count1 != count2)
{
return false;
}

if (count1 == 0 && count2 == 0)
{
return true;
}
}

if (equalityComparer == null)
{
equalityComparer = EqualityComparer<T>.Default;
}

// If we have generic types we can use, use them to avoid boxing.
var sequence2OfT = sequence2 as IEnumerable<T>;
var equalityComparerOfT = equalityComparer as IEqualityComparer<T>;
if (sequence2OfT != null && equalityComparerOfT != null)
{
return sequence1.SequenceEqual(sequence2OfT, equalityComparerOfT);
}
else
{
// We have to fall back to doing it manually since the underlying collection
// being compared isn't a (matching) generic type.
using (var enumerator = sequence1.GetEnumerator())
{
var enumerator2 = sequence2.GetEnumerator();
try
{
while (enumerator.MoveNext())
{
if (!enumerator2.MoveNext() || !equalityComparer.Equals(enumerator.Current, enumerator2.Current))
{
return false;
}
}

if (enumerator2.MoveNext())
{
return false;
}

return true;
}
finally
{
var enum2Disposable = enumerator2 as IDisposable;
if (enum2Disposable != null)
{
enum2Disposable.Dispose();
}
}
}
}
}

#endif

/// <summary>
/// Provides a known wrapper around a sequence of elements that provides the number of elements
/// and an indexer into its contents.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -412,16 +412,6 @@ private int ReadMembers(ClassDataContract classContract, bool[] requiredMembers,
_ilg.StoreMember(dataMember.MemberInfo);
}

#if FEATURE_LEGACYNETCF
// The DataContractSerializer in the .NET Framework doesn't support unordered elements:
// deserialization will fail if the data members in the XML are not sorted alphabetically.
// But the NetCF DataContractSerializer does support unordered element. To maintain compatibility
// with Mango we always search for the member from the beginning of the member list.
// We set memberIndexLocal to -1 because GetMemberIndex always starts from memberIndex+1.
if (CompatibilitySwitches.IsAppEarlierThanWindowsPhone8)
ilg.Set(memberIndexLocal, (int)-1);
else
#endif // FEATURE_LEGACYNETCF
_ilg.Set(memberIndexLocal, memberCount);

_ilg.EndCase();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3708,11 +3708,7 @@ private bool ParseXmlDeclaration(bool isTextDecl)
}

if (!XmlConvert.StrEqual(_ps.chars, _ps.charPos, 5, XmlDeclarationBeginning) ||
_xmlCharType.IsNameSingleChar(_ps.chars![_ps.charPos + 5])
#if XML10_FIFTH_EDITION
|| xmlCharType.IsNCNameHighSurrogateChar( ps.chars[ps.charPos + 5] )
#endif
)
_xmlCharType.IsNameSingleChar(_ps.chars![_ps.charPos + 5]))
{
goto NoXmlDecl;
}
Expand Down Expand Up @@ -3905,18 +3901,9 @@ private bool ParseXmlDeclaration(bool isTextDecl)
{
// version
case 0:
#if XML10_FIFTH_EDITION
// VersionNum ::= '1.' [0-9]+ (starting with XML Fifth Edition)
if (pos - ps.charPos >= 3 &&
ps.chars[ps.charPos] == '1' &&
ps.chars[ps.charPos + 1] == '.' &&
XmlCharType.IsOnlyDigits(ps.chars, ps.charPos + 2, pos - ps.charPos - 2))
{
#else
// VersionNum ::= '1.0' (XML Fourth Edition and earlier)
if (XmlConvert.StrEqual(_ps.chars, _ps.charPos, pos - _ps.charPos, "1.0"))
{
#endif
if (!isTextDecl)
{
Debug.Assert(attr != null);
Expand Down Expand Up @@ -4022,14 +4009,6 @@ private bool ParseXmlDeclaration(bool isTextDecl)
private bool ParseDocumentContent()
{
bool mangoQuirks = false;
#if FEATURE_LEGACYNETCF
// In Mango the default XmlTextReader is instantiated
// with v1Compat flag set to true. One of the effects
// of this settings is to eat any trailing nulls in the
// buffer and some apps depend on this behavior.
if (CompatibilitySwitches.IsAppEarlierThanWindowsPhone8)
mangoQuirks = true;
#endif
while (true)
{
bool needMoreChars = false;
Expand Down Expand Up @@ -4457,12 +4436,6 @@ private void ParseElement()
{
pos++;
}
#if XML10_FIFTH_EDITION
else if (pos + 1 < ps.charsUsed && xmlCharType.IsNCNameSurrogateChar(chars[pos + 1], chars[pos]))
{
pos += 2;
}
#endif
else
{
goto ParseQNameSlow;
Expand All @@ -4476,12 +4449,6 @@ private void ParseElement()
{
pos++;
}
#if XML10_FIFTH_EDITION
else if (pos < ps.charsUsed && xmlCharType.IsNCNameSurrogateChar(chars[pos + 1], chars[pos]))
{
pos += 2;
}
#endif
else
{
break;
Expand Down Expand Up @@ -4741,11 +4708,7 @@ private void ParseEndElement()
goto ReadData;
}

if (_xmlCharType.IsNCNameSingleChar(chars[pos]) || (chars[pos] == ':')
#if XML10_FIFTH_EDITION
|| xmlCharType.IsNCNameHighSurrogateChar(chars[pos])
#endif
)
if (_xmlCharType.IsNCNameSingleChar(chars[pos]) || (chars[pos] == ':'))
{
ThrowTagMismatch(startTagNode);
}
Expand Down Expand Up @@ -4888,12 +4851,6 @@ private void ParseAttributes()
{
startNameCharSize = 1;
}
#if XML10_FIFTH_EDITION
else if (pos + 1 < ps.charsUsed && xmlCharType.IsNCNameSurrogateChar(chars[pos + 1], tmpch1))
{
startNameCharSize = 2;
}
#endif

if (startNameCharSize == 0)
{
Expand Down Expand Up @@ -4966,12 +4923,6 @@ private void ParseAttributes()
{
pos++;
}
#if XML10_FIFTH_EDITION
else if (pos + 1 < ps.charsUsed && xmlCharType.IsNCNameSurrogateChar(chars[pos + 1], tmpch2))
{
pos += 2;
}
#endif
else
{
break;
Expand Down Expand Up @@ -5003,12 +4954,6 @@ private void ParseAttributes()
pos++;
goto ContinueParseName;
}
#if XML10_FIFTH_EDITION
else if ( pos + 1 < ps.charsUsed && xmlCharType.IsNCNameSurrogateChar( chars[pos + 1], chars[pos] ) ) {
pos += 2;
goto ContinueParseName;
}
#endif
// else fallback to full name parsing routine
pos = ParseQName(out colonPos);
chars = _ps.chars;
Expand Down Expand Up @@ -7730,12 +7675,6 @@ private int ParseQName(bool isQName, int startOffset, out int colonPos)
{
pos++;
}
#if XML10_FIFTH_EDITION
else if (pos + 1 < ps.charsUsed && xmlCharType.IsNCNameSurrogateChar(chars[pos + 1], chars[pos]))
{
pos += 2;
}
#endif
else
{
if (pos + 1 >= _ps.charsUsed)
Expand All @@ -7760,11 +7699,6 @@ private int ParseQName(bool isQName, int startOffset, out int colonPos)
{
pos++;
}
#if XML10_FIFTH_EDITION
else if ( pos + 1 < ps.charsUsed && xmlCharType.IsNCNameSurrogateChar( chars[pos + 1], chars[pos] ) ) {
pos += 2;
}
#endif
else
{
break;
Expand Down Expand Up @@ -7792,11 +7726,7 @@ private int ParseQName(bool isQName, int startOffset, out int colonPos)
}
}
// end of buffer
else if (pos == _ps.charsUsed
#if XML10_FIFTH_EDITION
|| ( pos + 1 == ps.charsUsed && xmlCharType.IsNCNameHighSurrogateChar( chars[pos] ) )
#endif
)
else if (pos == _ps.charsUsed)
{
if (ReadDataInName(ref pos))
{
Expand Down
Loading

0 comments on commit b3c7002

Please sign in to comment.