Created
March 4, 2012 19:27
-
-
Save jamesmanning/1974461 to your computer and use it in GitHub Desktop.
ctor for Buffer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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