• R/O
  • HTTP
  • SSH
  • HTTPS

FooEditEngine: Commit


Commit MetaInfo

Revision1b1fe1f2568c00d19bae47900ea1c8b318bf2784 (tree)
Time2021-01-05 21:31:15
Authortest <test@yaho...>
Commitertest

Log Message

ファイルロードを高速化した

Change Summary

Incremental Difference

--- a/Core/Document.cs
+++ b/Core/Document.cs
@@ -1124,12 +1124,13 @@ namespace FooEditEngine
11241124 /// </summary>
11251125 /// <param name="fs">IStreamReaderオブジェクト</param>
11261126 /// <param name="tokenSource">キャンセルトークン</param>
1127+ /// <param name="file_size">ファイルサイズ。-1を指定しても動作しますが、読み取りが遅くなります</param>
11271128 /// <returns>Taskオブジェクト</returns>
11281129 /// <remarks>
11291130 /// 読み取り操作は別スレッドで行われます。
11301131 /// また、非同期操作中はこのメソッドを実行することはできません。
11311132 /// </remarks>
1132- public async Task LoadAsync(TextReader fs, CancellationTokenSource tokenSource = null)
1133+ public async Task LoadAsync(TextReader fs, CancellationTokenSource tokenSource = null, int file_size = -1)
11331134 {
11341135 if (fs.Peek() == -1)
11351136 return;
@@ -1140,6 +1141,8 @@ namespace FooEditEngine
11401141 try
11411142 {
11421143 this.Clear();
1144+ if (file_size > 0)
1145+ this.buffer.Allocate(file_size);
11431146 await this.buffer.LoadAsync(fs, tokenSource);
11441147 }
11451148 finally
--- a/Core/GapBuffer.cs
+++ b/Core/GapBuffer.cs
@@ -385,6 +385,18 @@ namespace Slusser.Collections.Generic
385385 }
386386
387387
388+ /// <summary>
389+ /// Allocate buffer
390+ /// </summary>
391+ /// <param name="count">more than zero</param>
392+ public void Allocate(int count)
393+ {
394+ if(count > this._gapEnd - this._gapStart)
395+ {
396+ Capacity = count + count;
397+ }
398+ }
399+
388400 /// <summary>
389401 /// Searches for the specified object and returns the zero-based index of the first
390402 /// occurrence within the <see cref="GapBuffer{T}"/>.
--- a/Core/StringBuffer.cs
+++ b/Core/StringBuffer.cs
@@ -83,6 +83,11 @@ namespace FooEditEngine
8383
8484 internal DocumentUpdateEventHandler Update;
8585
86+ internal void Allocate(int count)
87+ {
88+ this.buf.Allocate(count);
89+ }
90+
8691 internal void Replace(StringBuffer buf)
8792 {
8893 this.Replace(buf.buf);
@@ -112,14 +117,10 @@ namespace FooEditEngine
112117
113118 internal async Task LoadAsync(TextReader fs, CancellationTokenSource tokenSource = null)
114119 {
115- char[] str = new char[1024 * 256];
120+ char[] str = new char[1024 * 1024];
116121 int readCount;
117122 do
118123 {
119- int index = this.Length;
120- if (index < 0)
121- index = 0;
122-
123124 readCount = await fs.ReadAsync(str, 0, str.Length).ConfigureAwait(false);
124125
125126 //内部形式に変換する
@@ -128,7 +129,7 @@ namespace FooEditEngine
128129 using (await this.rwlock.WriterLockAsync())
129130 {
130131 //str.lengthは事前に確保しておくために使用するので影響はない
131- this.buf.InsertRange(index, internal_str);
132+ this.buf.AddRange(internal_str);
132133 }
133134
134135 if (tokenSource != null)
Show on old repository browser