/// <param name="collection">The collection whose elements should be inserted into the <see cref="GapBuffer{T}"/>.
/// The collection itself cannot be null, but it can contain elements that are null, if
/// type <typeparamref name="T"/> is a reference type.</param>
- /// <param name="collectionCount">The count of collction.count is -1 when this method is slowly</param>
+ /// <param name="preallocatCount">The count of collction.count is -1 when this method is slowly</param>
/// <exception cref="ArgumentNullException"><paramref name="collection"/> is a null reference.</exception>
/// <exception cref="ArgumentOutOfRangeException">
/// <paramref name="index"/> is less than 0.
/// <para>-or-</para>
/// <paramref name="index"/> is greater than <see cref="Count"/>.
/// </exception>
- public void InsertRange(int index, IEnumerable<T> collection, int collectionCount = -1)
+ public void InsertRange(int index, IEnumerable<T> collection, int preallocatCount = -1)
{
if (collection == null)
throw new ArgumentNullException("collection");
if (index < 0 || index > Count)
throw new ArgumentOutOfRangeException("index", "");
- if (collectionCount == -1)
+ if (preallocatCount == -1)
{
// Add the items to the buffer one-at-a-time :(
using (IEnumerator<T> enumerator = collection.GetEnumerator())
}
}
}
- else if(collectionCount > 0)
+ else if(preallocatCount > 0)
{
PlaceGapStart(index);
- EnsureGapCapacity(collectionCount);
+ EnsureGapCapacity(preallocatCount);
+ int collectionLength = 0;
using (IEnumerator<T> enumerator = collection.GetEnumerator())
{
while (enumerator.MoveNext())
{
this._buffer[index] = enumerator.Current;
index++;
+ collectionLength++;
}
}
- this._gapStart += collectionCount;
+ this._gapStart += collectionLength;
}
this._version++;
readCount = await fs.ReadAsync(str, 0, str.Length).ConfigureAwait(false);\r
\r
//内部形式に変換する\r
- var internal_str = from s in str where s != '\r' select s;\r
+ var internal_str = from s in str where s != '\r' && s != '\0' select s;\r
\r
//str.lengthは事前に確保しておくために使用するので影響はない\r
this.buf.InsertRange(index, internal_str, str.Length);\r
#if TEST_ASYNC\r
System.Threading.Thread.Sleep(10);\r
#endif\r
+ Array.Clear(str, 0, str.Length);\r
} while (readCount > 0);\r
this.Update(this, new DocumentUpdateEventArgs(UpdateType.Clear, -1, -1, -1));\r
this.Update(this, new DocumentUpdateEventArgs(UpdateType.Replace, 0, 0, buf.Count));\r