perf: Moving enumerable extensions optimizations into correct place

This commit is contained in:
Chris Cameron
2018-11-08 16:15:22 -05:00
parent f53607018c
commit e21830a7d5

View File

@@ -58,7 +58,18 @@ namespace ICD.Common.Utils.Extensions
if (extends == null)
throw new ArgumentNullException("extends");
return extends.TryFirst(i => true, out item);
IList<T> list = extends as IList<T>;
if (list == null)
return extends.TryFirst(i => true, out item);
item = default(T);
if (list.Count <= 0)
return false;
item = list[0];
return true;
}
/// <summary>
@@ -106,7 +117,18 @@ namespace ICD.Common.Utils.Extensions
if (extends == null)
throw new ArgumentNullException("extends");
return extends.TryLast(i => true, out item);
IList<T> list = extends as IList<T>;
if (list == null)
return extends.TryLast(i => true, out item);
item = default(T);
if (list.Count <= 0)
return false;
item = list[list.Count - 1];
return true;
}
/// <summary>