Revision | 1b1fe1f2568c00d19bae47900ea1c8b318bf2784 (tree) |
---|---|
Time | 2021-01-05 21:31:15 |
Author | test <test@yaho...> |
Commiter | test |
ファイルロードを高速化した
@@ -1124,12 +1124,13 @@ namespace FooEditEngine | ||
1124 | 1124 | /// </summary> |
1125 | 1125 | /// <param name="fs">IStreamReaderオブジェクト</param> |
1126 | 1126 | /// <param name="tokenSource">キャンセルトークン</param> |
1127 | + /// <param name="file_size">ファイルサイズ。-1を指定しても動作しますが、読み取りが遅くなります</param> | |
1127 | 1128 | /// <returns>Taskオブジェクト</returns> |
1128 | 1129 | /// <remarks> |
1129 | 1130 | /// 読み取り操作は別スレッドで行われます。 |
1130 | 1131 | /// また、非同期操作中はこのメソッドを実行することはできません。 |
1131 | 1132 | /// </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) | |
1133 | 1134 | { |
1134 | 1135 | if (fs.Peek() == -1) |
1135 | 1136 | return; |
@@ -1140,6 +1141,8 @@ namespace FooEditEngine | ||
1140 | 1141 | try |
1141 | 1142 | { |
1142 | 1143 | this.Clear(); |
1144 | + if (file_size > 0) | |
1145 | + this.buffer.Allocate(file_size); | |
1143 | 1146 | await this.buffer.LoadAsync(fs, tokenSource); |
1144 | 1147 | } |
1145 | 1148 | finally |
@@ -385,6 +385,18 @@ namespace Slusser.Collections.Generic | ||
385 | 385 | } |
386 | 386 | |
387 | 387 | |
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 | + | |
388 | 400 | /// <summary> |
389 | 401 | /// Searches for the specified object and returns the zero-based index of the first |
390 | 402 | /// occurrence within the <see cref="GapBuffer{T}"/>. |
@@ -83,6 +83,11 @@ namespace FooEditEngine | ||
83 | 83 | |
84 | 84 | internal DocumentUpdateEventHandler Update; |
85 | 85 | |
86 | + internal void Allocate(int count) | |
87 | + { | |
88 | + this.buf.Allocate(count); | |
89 | + } | |
90 | + | |
86 | 91 | internal void Replace(StringBuffer buf) |
87 | 92 | { |
88 | 93 | this.Replace(buf.buf); |
@@ -112,14 +117,10 @@ namespace FooEditEngine | ||
112 | 117 | |
113 | 118 | internal async Task LoadAsync(TextReader fs, CancellationTokenSource tokenSource = null) |
114 | 119 | { |
115 | - char[] str = new char[1024 * 256]; | |
120 | + char[] str = new char[1024 * 1024]; | |
116 | 121 | int readCount; |
117 | 122 | do |
118 | 123 | { |
119 | - int index = this.Length; | |
120 | - if (index < 0) | |
121 | - index = 0; | |
122 | - | |
123 | 124 | readCount = await fs.ReadAsync(str, 0, str.Length).ConfigureAwait(false); |
124 | 125 | |
125 | 126 | //内部形式に変換する |
@@ -128,7 +129,7 @@ namespace FooEditEngine | ||
128 | 129 | using (await this.rwlock.WriterLockAsync()) |
129 | 130 | { |
130 | 131 | //str.lengthは事前に確保しておくために使用するので影響はない |
131 | - this.buf.InsertRange(index, internal_str); | |
132 | + this.buf.AddRange(internal_str); | |
132 | 133 | } |
133 | 134 | |
134 | 135 | if (tokenSource != null) |