Skip to content

Instantly share code, notes, and snippets.

@jamesmanning
Created March 4, 2012 19:27
Show Gist options
  • Save jamesmanning/1974461 to your computer and use it in GitHub Desktop.
Save jamesmanning/1974461 to your computer and use it in GitHub Desktop.
ctor for Buffer
internal Buffer(IEnumerable<TElement> source)
{
TElement[] tElementArray = null;
int count = 0;
ICollection<TElement> tElements = source as ICollection<TElement>;
if (tElements == null)
{
foreach (TElement tElement in source)
{
if (tElementArray != null)
{
if ((int)tElementArray.Length == count)
{
TElement[] tElementArray1 = new TElement[count * 2];
Array.Copy(tElementArray, 0, tElementArray1, 0, count);
tElementArray = tElementArray1;
}
}
else
{
tElementArray = new TElement[4];
}
tElementArray[count] = tElement;
count++;
}
}
else
{
count = tElements.Count;
if (count > 0)
{
tElementArray = new TElement[count];
tElements.CopyTo(tElementArray, 0);
}
}
this.items = tElementArray;
this.count = count;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment