public static SimpleList <T> SimpleTakeWhile <T>(this T[] source, Func <T, bool> predicate) { if (source == null) { throw new InvalidOperationException("Invalid null object"); } var result = new T[8]; var length = 8; var count = 0; int log = IntExtensions.Log2((uint)source.Length) - 3; log = log > 2 ? (log - (log % 2)) : 2; for (int i = 0; i < source.Length; i++) { if (!predicate(source[i])) { break; } if (count >= length) { EnlargeExtensions.LogEnlargeArray(2, source.Length, ref result, ref log, out length); } result[count] = source[i]; count++; } var final = new SimpleList <T>(); final.Items = result; final.Count = count; return(final); }
public static SimpleList <TResult> SimpleOfType <TSource, TResult>(this IList <TSource> source) { if (source == null) { throw new InvalidOperationException("Invalid null object"); } var sourceCount = source.Count; var result = new TResult[8]; var length = 8; var count = 0; int log = IntExtensions.Log2((uint)sourceCount) - 3; log = log > 2 ? (log - (log % 2)) : 2; for (int i = 0; i < sourceCount; i++) { if (!(source[i] is TResult retyped)) { continue; } if (count >= length) { EnlargeExtensions.LogEnlargeArray(2, sourceCount, ref result, ref log, out length); } result[count] = retyped; count++; } var final = new SimpleList <TResult>(); final.Items = result; final.Count = count; return(final); }