{
if (count <= 0)
return;
-
- if (driver.Initialized){
- lock (this){
- for (int i = 0; i < count; i++) {
- try {
- char val = buffer [index + i];
- if (driver.NotifyWrite (val))
- InternalWriteChar (val);
- } catch (IOException){
- }
- }
- }
- } else {
+
+ if (!driver.Initialized) {
try {
base.Write (buffer, index, count);
- } catch (IOException){
+ } catch (IOException) {
}
+
+ return;
+ }
+
+ lock (this) {
+ int i = 0, j = 0;
+ char []buf;
+ char c;
+
+ // The idea here is that we want to limit our temp
+ // buffer size - I picked 1k because the underlying
+ // stream implementation seems to break writes into
+ // 1k byte chunks.
+ if (count > 1024)
+ buf = new char[1024];
+ else
+ buf = new char[count];
+
+ do {
+ do {
+ c = buffer [index + i++];
+
+ if (driver.NotifyWrite (c)) {
+ buf[j++] = c;
+ break;
+ }
+ } while (i < count);
+
+ if (j == buf.Length || i == count) {
+ // temp buffer is full, write it out
+ try {
+ base.Write (buf, 0, j);
+ } catch (IOException) {
+ }
+
+ j = 0;
+ }
+ } while (i < count);
}
}
+2007-04-16 Jeffrey Stedfast <fejj@gnome.org>
+
+ * CStreamWriter.cs (Write): Instead of writing 1 char at a time,
+ copy the bytes into a temporary char array (with a fixed max size)
+ so that we can minimize the number of Write() calls we make on the
+ underlying stream (and thus on the write() system call).
+
2007-04-17 Alp Toker <alp@atoker.com>
* Array.cs: Make GetRank() icall private. Subclasses should use the