/// <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="count">The count of collction.count is -1 when this method is slowly</param>
/// <exception cref="ArgumentNullException"><paramref name="collection"/> is a null reference.</exception>
- public void AddRange(IEnumerable<T> collection,int count = -1)
+ public void AddRange(IEnumerable<T> collection)
{
- InsertRange(Count, collection,count);
+ InsertRange(Count, collection);
}
/// <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="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 preallocatCount = -1)
+ public void InsertRange(int index, IEnumerable<T> collection)
{
if (collection == null)
throw new ArgumentNullException("collection");
if (index < 0 || index > Count)
throw new ArgumentOutOfRangeException("index", "");
- if (preallocatCount == -1)
+ ICollection<T> col = collection as ICollection<T>;
+ if (col != null)
{
- // Add the items to the buffer one-at-a-time :(
- using (IEnumerator<T> enumerator = collection.GetEnumerator())
+ int count = col.Count;
+ if (count > 0)
{
- while (enumerator.MoveNext())
- {
- Insert(index, enumerator.Current);
- index++;
- }
+ PlaceGapStart(index);
+ EnsureGapCapacity(count);
+
+ // Copy the collection directly into the buffer
+ col.CopyTo(this._buffer, this._gapStart);
+ this._gapStart += count;
}
}
- else if(preallocatCount > 0)
+ else
{
- PlaceGapStart(index);
- EnsureGapCapacity(preallocatCount);
- int collectionLength = 0;
+ // Add the items to the buffer one-at-a-time :(
using (IEnumerator<T> enumerator = collection.GetEnumerator())
{
while (enumerator.MoveNext())
{
- this._buffer[index] = enumerator.Current;
+ Insert(index, enumerator.Current);
index++;
- collectionLength++;
}
}
- this._gapStart += collectionLength;
-
}
this._version++;
}
public StringBuffer(StringBuffer buffer)
: this()
{
- buf.AddRange(buffer.buf, buffer.Length);
+ buf.AddRange(buffer.buf);
}
{
if (length > 0)
this.buf.RemoveRange(index, length);
- this.buf.InsertRange(index, chars, count);
+ this.buf.InsertRange(index, chars);
}
this.Update(this, new DocumentUpdateEventArgs(UpdateType.Replace, index, length, count));
}
using (await this.rwlock.WriterLockAsync())
{
//str.lengthは事前に確保しておくために使用するので影響はない
- this.buf.InsertRange(index, internal_str, str.Length);
+ this.buf.InsertRange(index, internal_str);
}
if (tokenSource != null)
//空行は削除する必要はない
if (lineHeadIndex < this.buf.Count)
this.buf.RemoveRange(lineHeadIndex, lineLength);
- this.buf.InsertRange(lineHeadIndex, output, output.Length);
+ this.buf.InsertRange(lineHeadIndex, output);
}
this.Update(this, new DocumentUpdateEventArgs(UpdateType.Replace, lineHeadIndex, lineLength, output.Length, i));
using (this.rwlock.WriterLock())
{
this.buf.RemoveRange(right, target.Length);
- this.buf.InsertRange(right, pattern_chars, pattern.Length);
+ this.buf.InsertRange(right, pattern_chars);
}
left = right + pattern.Length;
newLineLength += pattern.Length - target.Length;
this.Buffer = buf;
this.ReplacementRange = new TextRange(start,str.Length);
this.replacement = new GapBuffer<char>();
- this.replacement.AddRange(Util.GetEnumrator(str),str.Length);
+ this.replacement.AddRange(Util.GetEnumrator(str));
this.ReplacedRange = new TextRange(start,length);
this.replaced = new GapBuffer<char>();
this.replaced.AddRange(this.Buffer.GetEnumerator(start, length));
int bufferIndex = cmd.ReplacedRange.Index - this.ReplacementRange.Index;
if(bufferIndex < this.replacement.Count)
this.replacement.RemoveRange(bufferIndex, cmd.ReplacedRange.Length);
- this.replacement.InsertRange(bufferIndex, cmd.replacement, cmd.replacement.Count);
+ this.replacement.InsertRange(bufferIndex, cmd.replacement);
return true;
}
if (this.ReplacedRange.Index + this.ReplacementRange.Length == cmd.ReplacedRange.Index &&
this.ReplacedRange.Index == this.ReplacementRange.Index)
{
- this.replaced.AddRange(cmd.replaced,cmd.replaced.Count);
- this.replacement.AddRange(cmd.replacement,cmd.replacement.Count);
+ this.replaced.AddRange(cmd.replaced);
+ this.replacement.AddRange(cmd.replacement);
this.ReplacedRange.Length += cmd.ReplacedRange.Length;
this.ReplacementRange.Length += cmd.ReplacementRange.Length;
return true;