Null-coalesce within enumerable types. (#1136)

Reduces field-access.
This commit is contained in:
Jon Hanna
2017-01-07 08:13:04 +13:00
committed by James Newton-King
parent f663060005
commit 0b187df8cb
2 changed files with 4 additions and 31 deletions
+1 -6
View File
@@ -67,12 +67,7 @@ namespace Newtonsoft.Json.Linq
/// </returns>
public IEnumerator<T> GetEnumerator()
{
if (_enumerable == null)
{
return Empty.GetEnumerator();
}
return _enumerable.GetEnumerator();
return (_enumerable ?? Empty).GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator()
@@ -169,24 +169,12 @@ namespace Newtonsoft.Json.Utilities
public virtual IEnumerator<T> GetEnumerator()
{
if (_genericCollection != null)
{
return _genericCollection.GetEnumerator();
}
return _list.Cast<T>().GetEnumerator();
return (_genericCollection ?? _list.Cast<T>()).GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator()
{
if (_genericCollection != null)
{
return _genericCollection.GetEnumerator();
}
else
{
return _list.GetEnumerator();
}
return ((IEnumerable)_genericCollection ?? _list).GetEnumerator();
}
int IList.Add(object value)
@@ -333,17 +321,7 @@ namespace Newtonsoft.Json.Utilities
public object UnderlyingCollection
{
get
{
if (_genericCollection != null)
{
return _genericCollection;
}
else
{
return _list;
}
}
get { return (object)_genericCollection ?? _list; }
}
}
}