OSDN Git Service

高速化のため読込部分をStringBufferに移動した
authorkonekoneko <test2214@hotmail.co.jp>
Wed, 8 Jul 2015 18:15:35 +0000 (03:15 +0900)
committerkonekoneko <test2214@hotmail.co.jp>
Wed, 8 Jul 2015 18:15:35 +0000 (03:15 +0900)
Common/Document.cs
Common/StringBuffer.cs

index 6d30330..71019f7 100644 (file)
@@ -521,27 +521,11 @@ namespace FooEditEngine
                 await this.LockAsync().ConfigureAwait(false);\r
                 this.Clear();\r
                 this.FireUpdateEvent = false;\r
-                this.UndoManager.BeginLock();\r
-                string str;\r
-                for (int i = 0; (str = await fs.ReadLineAsync().ConfigureAwait(false)) != null; i++)\r
-                {\r
-                    int index = this.Length;\r
-                    if (index < 0)\r
-                        index = 0;\r
-\r
-                    this.Replace(index, 0, str + Document.NewLine);\r
-\r
-                    if (tokenSource != null)\r
-                        tokenSource.Token.ThrowIfCancellationRequested();\r
-#if TEST_ASYNC\r
-                    System.Threading.Thread.Sleep(10);\r
-#endif\r
-                }\r
+                await this.buffer.LoadAsync(fs, tokenSource);\r
             }\r
             finally\r
             {\r
                 this.FireUpdateEvent = true;\r
-                this.UndoManager.EndLock();\r
                 this.UnLock();\r
             }\r
         }\r
index e83e1a1..dcc97a7 100644 (file)
@@ -14,6 +14,7 @@ using System.Globalization;
 using System.Linq;\r
 using System.Text;\r
 using System.Threading;\r
+using System.Threading.Tasks;\r
 using Slusser.Collections.Generic;\r
 \r
 namespace FooEditEngine\r
@@ -135,6 +136,27 @@ namespace FooEditEngine
             this.Update(this, new DocumentUpdateEventArgs(UpdateType.Replace, index, length, count));\r
         }\r
 \r
+        internal async Task LoadAsync(IStreamReader fs, CancellationTokenSource tokenSource = null)\r
+        {\r
+            string str;\r
+            for (int i = 0; (str = await fs.ReadLineAsync().ConfigureAwait(false)) != null; i++)\r
+            {\r
+                int index = this.Length;\r
+                if (index < 0)\r
+                    index = 0;\r
+\r
+                this.buf.InsertRange(index, str + Document.NewLine, str.Length + 1);\r
+\r
+                if (tokenSource != null)\r
+                    tokenSource.Token.ThrowIfCancellationRequested();\r
+#if TEST_ASYNC\r
+                    System.Threading.Thread.Sleep(10);\r
+#endif\r
+            }\r
+            this.Update(this, new DocumentUpdateEventArgs(UpdateType.Clear, -1, -1, -1));\r
+            this.Update(this, new DocumentUpdateEventArgs(UpdateType.Replace, 0, 0, buf.Count));\r
+        }\r
+\r
         internal void Replace(string target, string pattern,bool ci = false)\r
         {\r
             TextSearch ts = new TextSearch(target,ci);\r