/// </summary>
/// <param name="fs">IStreamReaderオブジェクト</param>
/// <param name="tokenSource">キャンセルトークン</param>
+ /// <param name="file_size">ファイルサイズ。-1を指定しても動作しますが、読み取りが遅くなります</param>
/// <returns>Taskオブジェクト</returns>
/// <remarks>
/// 読み取り操作は別スレッドで行われます。
/// また、非同期操作中はこのメソッドを実行することはできません。
/// </remarks>
- public async Task LoadAsync(TextReader fs, CancellationTokenSource tokenSource = null)
+ public async Task LoadAsync(TextReader fs, CancellationTokenSource tokenSource = null, int file_size = -1)
{
if (fs.Peek() == -1)
return;
try
{
this.Clear();
+ if (file_size > 0)
+ this.buffer.Allocate(file_size);
await this.buffer.LoadAsync(fs, tokenSource);
}
finally
}
+ /// <summary>
+ /// Allocate buffer
+ /// </summary>
+ /// <param name="count">more than zero</param>
+ public void Allocate(int count)
+ {
+ if(count > this._gapEnd - this._gapStart)
+ {
+ Capacity = count + count;
+ }
+ }
+
/// <summary>
/// Searches for the specified object and returns the zero-based index of the first
/// occurrence within the <see cref="GapBuffer{T}"/>.
internal DocumentUpdateEventHandler Update;
+ internal void Allocate(int count)
+ {
+ this.buf.Allocate(count);
+ }
+
internal void Replace(StringBuffer buf)
{
this.Replace(buf.buf);
internal async Task LoadAsync(TextReader fs, CancellationTokenSource tokenSource = null)
{
- char[] str = new char[1024 * 256];
+ char[] str = new char[1024 * 1024];
int readCount;
do
{
- int index = this.Length;
- if (index < 0)
- index = 0;
-
readCount = await fs.ReadAsync(str, 0, str.Length).ConfigureAwait(false);
//内部形式に変換する
using (await this.rwlock.WriterLockAsync())
{
//str.lengthは事前に確保しておくために使用するので影響はない
- this.buf.InsertRange(index, internal_str);
+ this.buf.AddRange(internal_str);
}
if (tokenSource != null)