}
+ /// <summary>
+ /// Inserts the elements of a collection into the <see cref="GapBuffer{T}"/> at the specified index.
+ /// Consecutive operations at or near previous inserts are optimized.
+ /// </summary>
+ /// <param name="index">The zero-based index at which the new elements should be inserted.</param>
+ /// <param name="col">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>
+ /// <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, ICollection<T> col)
+ {
+ if (col == null)
+ throw new ArgumentNullException("collection");
+
+ if (index < 0 || index > Count)
+ throw new ArgumentOutOfRangeException("index", "");
+
+ if (col != null)
+ {
+ int count = col.Count;
+ if (count > 0)
+ {
+ PlaceGapStart(index);
+ EnsureGapCapacity(count);
+
+ // Copy the collection directly into the buffer
+ col.CopyTo(this._buffer, this._gapStart);
+ this._gapStart += count;
+ }
+ }
+ this._version++;
+ }
/// <summary>
/// Inserts the elements of a collection into the <see cref="GapBuffer{T}"/> at the specified index.
/// Consecutive operations at or near previous inserts are optimized.
if (index < 0 || index > Count)
throw new ArgumentOutOfRangeException("index", "");
- ICollection<T> col = collection as ICollection<T>;
- if (col != null)
- {
- int count = col.Count;
- if (count > 0)
- {
- PlaceGapStart(index);
- EnsureGapCapacity(count);
-
- // Copy the collection directly into the buffer
- col.CopyTo(this._buffer, this._gapStart);
- this._gapStart += count;
- }
- }
- else if (collectionCount == -1)
+ if (collectionCount == -1)
{
// Add the items to the buffer one-at-a-time :(
using (IEnumerator<T> enumerator = collection.GetEnumerator())