OSDN Git Service

ゴミがついてしまうバグを修正した
authorkonekoneko <test2214@hotmail.co.jp>
Wed, 8 Jul 2015 19:06:19 +0000 (04:06 +0900)
committerkonekoneko <test2214@hotmail.co.jp>
Wed, 8 Jul 2015 19:06:19 +0000 (04:06 +0900)
Common/GapBuffer.cs
Common/StringBuffer.cs

index efd4733..a0b8bc2 100644 (file)
@@ -501,14 +501,14 @@ namespace Slusser.Collections.Generic
                /// <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");
@@ -516,7 +516,7 @@ namespace Slusser.Collections.Generic
             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())
@@ -528,19 +528,21 @@ namespace Slusser.Collections.Generic
                     }
                 }
             }
-            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++;
index f2d5a82..8abd5c9 100644 (file)
@@ -149,7 +149,7 @@ namespace FooEditEngine
                 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
@@ -159,6 +159,7 @@ namespace FooEditEngine
 #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