[Mono-devel-list] [PATCH] StringBuilder Speedup

Ben Maurer bmaurer at ximian.com
Wed Jan 19 17:24:12 EST 2005


On Wed, 2005-01-19 at 16:18 -0500, Gonzalo Paniagua Javier wrote:
> On Sat, 2005-01-15 at 23:19 -0500, Ben Maurer wrote:
> [...]
> > Case 3:
> > 
> > {
> > 	StringBuilder sb = new StringBuilder ();
> > 	sb.Append ("0123456789");
> > 	sb.Append ("0123456789");
> > 	sb.ToString ();
> > }
> > 
> > We saved one allocation here. The default size of a StringBuilder is 16.
> > However, in the second append, it knows that this will not be large
> > enough. So it is able to make its first buffer 32 chars.
> 
> I'd rather stick to having the same capacity as they have and growing in
> the same way. We already have tests for that and there's no need to
> break it fr getting a small speedup or memory saving.

Microsoft does similar changes between versions. I know they did
something like this for ArrayList in 2.0.

MSDN clearly specifies this as impl defined behavior.

-- Ben




More information about the Mono-devel-list mailing list