[Mono-devel-list] streamwriter fixes
Ben Maurer
bmaurer at users.sourceforge.net
Mon Aug 18 22:47:34 EDT 2003
On Mon, 2003-08-18 at 12:39, Paolo Molaro wrote:
> I had these fixes in my tree for a few months, but I can't say
> I have tested them much. This should get the writer classes closer to
> the documentation (which says only Write(char) must be implemented by a
> subclass, previous code had Wrute(char[]) as the required method to
> implement in a derived class) and it may give a small speedup, since
> decoding is done in largers buffers at a time.
> Please test and review.
>
> lupus
Actually, in XmlTextWriter, this patch helps out alot with memory
allocation.
One other speedup we can do is to not call .ToCharArray () in
WriteString:
public override void Write (string value) {
if (DisposedAlready)
throw new ObjectDisposedException("StreamWriter");
int index = 0, count = value.Length;
while (count > 0) {
int todo = decode_buf.Length - decode_pos;
if (todo == 0) {
Decode ();
todo = decode_buf.Length;
}
if (todo > count)
todo = count;
value.CopyTo (index, decode_buf, decode_pos, todo);
count -= todo;
index += todo;
decode_pos += todo;
}
if (iflush)
Flush ();
}
That saves us a char [] for each call.
-- Ben
More information about the Mono-devel-list
mailing list