/// ストリームから行を読み取った物を返す。LoadAsyncを呼び出す場合は必ず実装してください\r
/// </summary>\r
Task<string> ReadLineAsync();\r
+ /// <summary>\r
+ /// ストリームから指定した文字数だけ読み取る\r
+ /// </summary>\r
+ /// <param name="buffer">書き込み先バッファー</param>\r
+ /// <param name="index">書き込み先バッファーのインデックス</param>\r
+ /// <param name="count">読み取る文字数</param>\r
+ /// <returns>読み取った文字数</returns>\r
+ Task<int> ReadAsync(char[] buffer, int index, int count);\r
}\r
\r
public interface IStreamWriter\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
+ char[] str = new char[1024 * 256];\r
+ int readCount;\r
+ do\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
+ 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
+\r
+ //str.lengthは事前に確保しておくために使用するので影響はない\r
+ this.buf.InsertRange(index, internal_str, str.Length);\r
\r
if (tokenSource != null)\r
tokenSource.Token.ThrowIfCancellationRequested();\r
#if TEST_ASYNC\r
System.Threading.Thread.Sleep(10);\r
#endif\r
- }\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
}\r
return this.sr.ReadLineAsync();
}
+ public Task<int> ReadAsync(char[] buffer,int index, int count)
+ {
+ return this.sr.ReadAsync(buffer, index, count);
+ }
+
+
public void Close()
{
#if !METRO