Author: zoltan
Date: 2008-02-09 17:56:18 -0500 (Sat, 09 Feb 2008)
New Revision: 95346
Modified:
trunk/mcs/class/corlib/System.IO/ChangeLog
trunk/mcs/class/corlib/System.IO/UnexceptionalStreamReader.cs
Log:
2008-02-10 Zoltan Varga <[EMAIL PROTECTED]>
* UnexceptionalStreamReader.cs (Read): Optimize this to avoid making a
number of
calls + creation of a string for each character read.
Modified: trunk/mcs/class/corlib/System.IO/ChangeLog
===================================================================
--- trunk/mcs/class/corlib/System.IO/ChangeLog 2008-02-09 22:33:27 UTC (rev
95345)
+++ trunk/mcs/class/corlib/System.IO/ChangeLog 2008-02-09 22:56:18 UTC (rev
95346)
@@ -1,3 +1,8 @@
+2008-02-10 Zoltan Varga <[EMAIL PROTECTED]>
+
+ * UnexceptionalStreamReader.cs (Read): Optimize this to avoid making a
number of
+ calls + creation of a string for each character read.
+
2008-02-03 Sebastien Pouliot <[EMAIL PROTECTED]>
* MemoryStream.cs: Remove unused code found by Gendarme.
Modified: trunk/mcs/class/corlib/System.IO/UnexceptionalStreamReader.cs
===================================================================
--- trunk/mcs/class/corlib/System.IO/UnexceptionalStreamReader.cs
2008-02-09 22:33:27 UTC (rev 95345)
+++ trunk/mcs/class/corlib/System.IO/UnexceptionalStreamReader.cs
2008-02-09 22:56:18 UTC (rev 95346)
@@ -42,8 +42,16 @@
namespace System.IO {
internal class UnexceptionalStreamReader : StreamReader {
- private bool[] newline = new bool [Environment.NewLine.Length];
+ private static bool[] newline = new bool
[Environment.NewLine.Length];
+ private static char newlineChar;
+
+ static UnexceptionalStreamReader () {
+ string n = Environment.NewLine;
+ if (n.Length == 1)
+ newlineChar = n [0];
+ }
+
public UnexceptionalStreamReader(Stream stream)
: base (stream)
{
@@ -128,26 +136,34 @@
throw new ArgumentException ("index + count >
dest_buffer.Length");
int chars_read = 0;
- while (count > 0) {
- int c = Read ();
- if (c < 0)
- break;
- chars_read++;
- count--;
+ char nl = newlineChar;
+ try {
+ while (count > 0) {
+ int c = base.Read ();
+ if (c < 0)
+ break;
+ chars_read++;
+ count--;
- dest_buffer [index] = (char) c;
- if (CheckEOL (dest_buffer [index++]))
- return chars_read;
+ dest_buffer [index] = (char) c;
+ // shortcut when a new line is only one
character (e.g. Linux, Mac)
+ if (nl != (char)0) {
+ if ((char)c == nl)
+ return chars_read;
+ } else {
+ if (CheckEOL ((char)c))
+ return chars_read;
+ }
+ index ++;
+ }
+ } catch (IOException) {
}
+
return chars_read;
}
private bool CheckEOL (char current)
{
- // shortcut when a new line is only one character (e.g.
Linux, Mac)
- if (newline.Length == 1)
- return (current == Environment.NewLine [0]);
-
// general case for any length (e.g. Windows)
for (int i=0; i < newline.Length; i++) {
if (!newline [i]) {
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches