From 000f1fb3cc2b56fe3858b6dd9e4e42c1c5a5eb86 Mon Sep 17 00:00:00 2001 From: Ben Maurer Date: Sat, 28 Aug 2004 13:12:30 +0000 Subject: [PATCH] 2004-08-26 Ben Maurer * StreamWriter.cs: avoid String.ToCharArray for perf. svn path=/branches/mono-1-0/mcs/; revision=32967 --- mcs/class/corlib/System.IO/ChangeLog | 4 ++++ mcs/class/corlib/System.IO/StreamWriter.cs | 25 ++++++++++++++++++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/mcs/class/corlib/System.IO/ChangeLog b/mcs/class/corlib/System.IO/ChangeLog index 75d3b48b95b..66166036581 100644 --- a/mcs/class/corlib/System.IO/ChangeLog +++ b/mcs/class/corlib/System.IO/ChangeLog @@ -1,3 +1,7 @@ +2004-08-26 Ben Maurer + + * StreamWriter.cs: avoid String.ToCharArray for perf. + 2004-08-18 Dick Porter * StreamWriter.cs: Flush the buffer if AutoFlush is set to true. diff --git a/mcs/class/corlib/System.IO/StreamWriter.cs b/mcs/class/corlib/System.IO/StreamWriter.cs index 96ac1380984..1799d74e6e6 100644 --- a/mcs/class/corlib/System.IO/StreamWriter.cs +++ b/mcs/class/corlib/System.IO/StreamWriter.cs @@ -249,6 +249,28 @@ namespace System.IO { index += todo; decode_pos += todo; } + } + + void LowLevelWrite (string s) + { + int count = s.Length; + int index = 0; + while (count > 0) { + int todo = decode_buf.Length - decode_pos; + if (todo == 0) { + Decode (); + todo = decode_buf.Length; + } + if (todo > count) + todo = count; + + for (int i = 0; i < todo; i ++) + decode_buf [i + decode_pos] = s [i + index]; + + count -= todo; + index += todo; + decode_pos += todo; + } } public override void Write (char value) @@ -282,7 +304,8 @@ namespace System.IO { throw new ObjectDisposedException("StreamWriter"); if (value != null) - LowLevelWrite (value.ToCharArray (), 0, value.Length); + LowLevelWrite (value); + if (iflush) Flush (); } -- 2.11.4.GIT